Skip to content

Commit

Permalink
adds a shortcut to avoid reconstructing every call
Browse files Browse the repository at this point in the history
When there is a loop trying to get scan / tile info that is ignoring
return values, add a shortcut to avoid trying to reconstruct the chunk
table every time. This will still respect the strict header flag, either
returning an error immediately (strict), or (non-strict) enabling a
multi-part file with only partially corrupt parts to work.

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Feb 10, 2024
1 parent b56b9b0 commit 83a8a5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/lib/OpenEXRCore/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand All @@ -609,15 +611,16 @@ 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);
}
}

*chunktable = ctable;
return EXR_ERR_SUCCESS;
return ((uintptr_t)ctable) == UINTPTR_MAX ? EXR_ERR_BAD_CHUNK_LEADER : EXR_ERR_SUCCESS;
}

/**************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OpenEXRCore/internal_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**************************************/
Expand Down

0 comments on commit 83a8a5f

Please sign in to comment.