Re: 4 byte length storage
John Bowler <[email protected]>
| Newsgroups | gmane.comp.graphics.png.devel |
|---|---|
| Message-ID | <CAP7U39-fHMW8SdLtSPM8bp05e-nSzisG1fwxLDMemAPY7FNX0w@mail.gmail.com> |
On Tue, Dec 6, 2016 at 10:04 AM, Andreas Kleinert <[email protected]> wrote: > Thus if sizeof(uint32_t) does not equal 4 I would consider this a good reason to stop compiling ;-) As machine sizes get bigger there is a temptation and potential benefit from making the smallest addressable unit larger. Indeed on the original ARM the smallest unit was a full 32 bits; bytes were handled in a somewhat complex way and 16-bit quantities weren't handled at all. libpng does stop compiling is UCHAR_MAX is not 255, but that's mainly because I have no way of testing it! It's moot in this case because the OP did not disclose the implementation of get_index; we don't know what fixups it is doing. I suspect it is doing none; just returning a pointer into memory. So when the first chunk, IHDR, is read the memory access is at <buffer>+12. We know that doesn't crash and that it returns a frobnicated "13". If the "13" is de-frobnicated then the next chunk length field is at <buffer>+8[header]+8[IHDR{length,IHDR}]+13[IHDR data]+4[IHDR crc}, which is <buffer>+33 and the code crashes on the indirection (on most modern machines)! In C++ the string "reinterpret_cast" means "undefined behavior" ;-) John Bowler ------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today.http://sdm.link/xeonphi