diff --git a/src/lib/OpenEXRCore/chunk.c b/src/lib/OpenEXRCore/chunk.c index 304a402cc..89f582dc9 100644 --- a/src/lib/OpenEXRCore/chunk.c +++ b/src/lib/OpenEXRCore/chunk.c @@ -590,13 +590,15 @@ extract_chunk_table ( // something similar, except when in strict mode, we // will fail with a corrupt chunk immediately. rv = reconstruct_chunk_table (ctxt, part, ctable); - if (rv != EXR_ERR_SUCCESS && ctxt->strict_header) + if (rv != EXR_ERR_SUCCESS) { ctxt->free_fn (ctable); - return ctxt->report_error ( - ctxt, - EXR_ERR_BAD_CHUNK_LEADER, - "Incomplete / corrupt chunk table, unable to reconstruct"); + ctable = (uint64_t*) UINTPTR_MAX; + if (ctxt->strict_header) + return ctxt->report_error ( + ctxt, + EXR_ERR_BAD_CHUNK_LEADER, + "Incomplete / corrupt chunk table, unable to reconstruct"); } } } @@ -609,7 +611,8 @@ extract_chunk_table ( &eptr, nptr)) { - ctxt->free_fn (ctable); + if (nptr != UINTPTR_MAX) + ctxt->free_fn (ctable); ctable = (uint64_t*) eptr; if (ctable == NULL) return ctxt->standard_error (ctxt, EXR_ERR_OUT_OF_MEMORY); @@ -617,7 +620,7 @@ extract_chunk_table ( } *chunktable = ctable; - return EXR_ERR_SUCCESS; + return ((uintptr_t)ctable) == UINTPTR_MAX ? EXR_ERR_BAD_CHUNK_LEADER : EXR_ERR_SUCCESS; } /**************************************/ diff --git a/src/lib/OpenEXRCore/internal_structs.c b/src/lib/OpenEXRCore/internal_structs.c index ef39ca46d..477e2872e 100644 --- a/src/lib/OpenEXRCore/internal_structs.c +++ b/src/lib/OpenEXRCore/internal_structs.c @@ -174,7 +174,7 @@ internal_exr_destroy_part ( ctable = (uint64_t*) atomic_load (&(cur->chunk_table)); atomic_store (&(cur->chunk_table), (uintptr_t) (0)); #endif - if (ctable) dofree (ctable); + if (ctable && ((uintptr_t)ctable) != UINTPTR_MAX) dofree (ctable); } /**************************************/