From 87c0d7dc1eee2adf1aa7ae31bdfac078bb114c01 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 8 Jan 2016 19:38:45 +0100 Subject: [PATCH 1/2] [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. --- src/lib/openjp2/dwt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index d63c120e..43498bdc 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -409,7 +409,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size); - if (! bj) { + if (l_data_size != 0 && ! bj) { return OPJ_FALSE; } i = l; From 6a1974d40d95d857377a1eb5f4db0d9e24d0ad0a Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sat, 9 Jan 2016 14:30:48 +0100 Subject: [PATCH 2/2] Add comment explaining bj is not use when l_data_size == 0 --- src/lib/openjp2/dwt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index 43498bdc..a4ff01ba 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -409,6 +409,8 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size); + /* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */ + /* in that case, so do not error out */ if (l_data_size != 0 && ! bj) { return OPJ_FALSE; }