-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid taking address of packed member #750
Comments
I know that this approach is in general unsafe. However, for BMP it's a simple approach that works on all platforms tested and has been extensively fuzzed. Besides being simple, I'm following "if it isn't broken, don't 'fix' it". If you'd like to redo the code to avoid the compiler warning, have at it :-) |
It actually crashes the testsuite on sparc64:
with the following backtrace:
Full build log at: https://buildd.debian.org/status/fetch.php?pkg=leptonlib&arch=sparc64&ver=1.84.1-4&stamp=1728101108&raw=0 |
All 3 test failures on sparc64 (ioformats_reg, mtiff_reg and pngio_reg) are due to this alignment problem reading bmp into memory. |
* The bmp infoheader on the sparc64 is not aligned on a 32-bit word, so read the data byte by byte.
Thank you for filing the detailed bug report. |
I'm afraid it is now wrong on big endian machines, but can make a test and send a fix. |
Thanks, Stefan. It works on little-endians, which is why I added the call to |
I can confirm that the alignment issues are gone but the testsuite is now failing for different reasons (sparc64 is big-endian as well):
|
Pull request #752 should fix it. I could not test |
Yes, that fixes it. However, I'm left with one more failing test now:
Edit: This seems to be an unrelated failure and more like an issue with my environment. |
Yes, I suspect it's a gnuplot issue in your environment. That command file only has 3 lines:
and for some reason the last two characters of the 3rd line have been put on line 4. |
Yep, that fixes it:
That's the master branch plus #752 and #753. Thanks for fixing it! |
Thanks for the test! |
* Cast byte to uint32 before left-shifting by 24, to avoid possible overflow.
The compiler warnings about taking the address of packed data is fixed with PR #754 |
Is the fix ready to be patched into Debian, or are things still in flux? |
I suggest to use either the master branch (which contains additional improvements), or use at least src/bmpio.c from the master branch (which is sufficient to fix the reported bug). |
If only taking files, you should also take src/bmp.h |
I'm looking for guidance. I could wait for 1.85, wait for a 1.85 release candidate, or patch in src/bmp.[ch]. However, I don't want to use the master branch without clear version numbers involved; it would make bug reports too confusing. Please note that Debian had a memory alignment bug report from 1.84.1 involving the rust bindings that is getting figured out. It may be completely unrelated and just need regeneration of the bindings. https://ci.debian.net/packages/r/rust-leptonica-sys/testing/i386/52950971/#S7 |
It's time I release 1.85. I'll try to do it in the next 2 days, and it will give you more options. |
Based on previous experience, please consider calling it a release candidate. If no little gotchas are found then the release can be exactly the same as the release candidate. |
I've always described the releases thus: Do you want me to say instead: |
I don't expect little gotchas in the release because nearly all changes are fixes or better documentation as far as I see. Therefore I think that it's sufficient to make a normal release. If there really were problems with the new release, another bugfix release could follow. |
OK. 1.85.0 is on github. |
Oops, didn't change CMakeLists version number. |
1.85.0 should be OK. |
Compiling the codebase with
-Waddress-of-packed-member
produces multiple errors at build time:Taking the address of a packed member is dangerous since the reduced alignment of the pointee is lost. This can lead to memory alignment faults in some architectures if the pointer value is dereferenced.
The text was updated successfully, but these errors were encountered: