-
Notifications
You must be signed in to change notification settings - Fork 455
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
[git/2.1 regression] Fix opj_write_tile() failure when numresolutions=1 #690
[git/2.1 regression] Fix opj_write_tile() failure when numresolutions=1 #690
Conversation
When trying the GDAL OpenJPEG driver against openjpeg current master HEAD, I get failures when trying to create .jp2 files. The driver uses opj_write_tile() and in some tests numresolutions = 1. In openjp2/dwt.c:410, l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); is called and returns l_data_size = 0. Now in git opj_malloc() has a special case for 0 to return a NULL pointer whereas previously it relied on system malloc(), which in my case didn't return NULL. So only test the pointer value if l_data_size != 0. This makes the GDAL autotest suite to pass again.
Maybe it would be better to return a pointer to a fixed address which points to const memory instead of returning NULL. Then callers would not need special handling. |
Well you'd have also to make a special case in opj_free() to not free this address. Another solution would be to do malloc(1) when opj_malloc(0) is called |
Sure, opj_free must ignore that address. Using malloc would only be an option if it had the same defined behavior on all platforms when called with 0. |
I suggested using malloc(1) |
Could you please handle the case |
@malaterre Not sure to understand what you mean. It is the nominal case handled by the code after the if (l_data_size != 0 && ! bj) check. What I know is that with my patch things work again as in 2.1 |
Hum, or perhaps do you mean that if tilec->numresolutions == 1 we could do an early exit return OPJ_TRUE at the beginning of the function ? (since when looking closer the code after the if (l_data_size != 0 && ! bj) check ends up not entering the while (i--) loop ) |
@rouault my bad. Could you please add comment stating that |
Comment added per 6a1974d |
…cedure [git/2.1 regression] Fix opj_write_tile() failure when numresolutions=1
When trying the GDAL OpenJPEG driver against openjpeg current master HEAD,
I get failures when trying to create .jp2 files. The driver uses
opj_write_tile() and in some tests numresolutions = 1.
In openjp2/dwt.c:410, l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
is called and returns l_data_size = 0. Now in git opj_malloc() has a special case
for 0 to return a NULL pointer whereas previously it relied on system malloc(),
which in my case didn't return NULL.
So only test the pointer value if l_data_size != 0. This makes the GDAL
autotest suite to pass again.