gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnash-dev] Alignment in AMF data


From: Russ Nelson
Subject: Re: [Gnash-dev] Alignment in AMF data
Date: Fri, 24 Oct 2008 02:16:38 -0400

Justin Dick writes:
 > I'm getting bus errors on my system in amf_read_value().  Specifically, the
 > buffer appears to contain a NUMBER_AMF0 type, which is then reinterpreted as
 > a double.  The problem is that the position in the buffer (well, the memory
 > address of the double) is 0x101c2d33, which is not aligned to the size of a
 > double.  This fails on my MIPS machine, which has strict alignment rules.
 > 
 > Is it legal to pack data like this in an AMF stream?  Or do I have some
 > other data corruption issue higher up the call stack?

Unfortunately, fetching full-sized data from a buffer is subject to
alignment problems.  Rob (our fearless leader) doesn't like the
following code, but it never has byte sex or alignment problems, and
there's never any ambiguity about exactly what you're loading.

            double ddd;
            uint8 *bbb = (uint8 *)el->getData();
            ddd  = (bbb[0] << 24);
            ddd |= (bbb[1] << 16);
            ddd |= (bbb[2] <<  8);
            ddd |= (bbb[3] <<  0);

I'm not sure that counting from 0 -> 3 is correct because I never know
when to byteswap and when not to.  I've seen code (not in gnash) where
the author was equally confused and didn't byte-swap when he had to.
Perhaps it needs to be counting from 3 -> 0.  The only way to find out
for sure is to look at the definition of the data stream.

-- 
--my blog is at    http://blog.russnelson.com   | Unregulation is a slippery
Crynwr sells support for free software  | PGPok | slope to prosperity and
521 Pleasant Valley Rd. | +1 315-323-1241       | freedom.
Potsdam, NY 13676-3213  |     Sheepdog          | 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]