-
Notifications
You must be signed in to change notification settings - Fork 456
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
Implementation-defined behavior of malloc causes different behavior on Linux and AIX #635
Labels
Milestone
Comments
I thought about that. But one would need to be somewhat smart with opj_malloc(0). What should we do: always return malloc(1); only return malloc(1) on AIX ? |
I think the C code instead should be fixes, malloc(0) feels so awkward. |
Agreed, I was more thinking that |
I was thinking of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was reproduced with AIX and Linux builds with the current HEAD revision ee04854 of OpenJPEG.
JPEG 2000 image that demonstrates the problem (save as
impldef.jp2
, GitHub wouldn't let me attach a.jp2
file):When the image is decompressed on Linux, opj_decompress converts the image successfully:
Attempting to decompress the image on AIX creates the following output (decompression fails):
I tracked this down to the following code in tcd.c starting at line 932:
When I enable the debug fprintf, the following output is produced:
recinct_ch = 0
causesl_nb_code_blocks
andl_nb_code_blocks_size
to be 0, and that causes an attempt to allocate 0 bytes in the linel_current_precinct->cblks.blocks = opj_malloc(l_nb_code_blocks_size);
.The problem is that attempts to allocate 0 bytes cause implementation-defined behavior.
malloc
may return a non-null or a null pointer. For example from the Open Group documentation on malloc:malloc on AIX decides to return a null pointer, and therefore the function
opj_tcd_init_tile
fails. On Linux and other platforms that I tested on malloc returns a non-null pointer, and decompression succeeds.Apparently the test image is broken according to OpenJPEG warnings, but nevertheless the behavior of OpenJPEG should be consistent across platforms and not be different because of implementation-defined behavior of
malloc
.The text was updated successfully, but these errors were encountered: