Skip to content

Commit

Permalink
Avoid oss fuzz checks in c++ by initializing scans differently
Browse files Browse the repository at this point in the history
Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed May 5, 2024
1 parent c6b7e96 commit ae646ec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/lib/OpenEXR/ImfDeepScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@ readSampleCountForLineBlock (
int sampleCountMinY,
bool writeToSlice)
{
if (lineBlockId < 0 || lineBlockId >= (int) data->lineOffsets.size ())
{
THROW (IEX_NAMESPACE::ArgExc,
"Invalid line block id: " << lineBlockId);
}

streamData->is->seekg (data->lineOffsets[lineBlockId]);

if (isMultiPart (data->version))
Expand Down
4 changes: 3 additions & 1 deletion src/lib/OpenEXR/ImfScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ void ScanLineInputFile::Data::readPixels (
<< dw.min.y << " - " << dw.max.y);
}

nchunks = 1 + (((int64_t) scanLine2 - (int64_t) scanLine1) / (int64_t) scansperchunk);
nchunks = ((int64_t) scanLine2 - (int64_t) scanLine1);
nchunks /= (int64_t) scansperchunk;
nchunks += 1;

exr_chunk_info_t cinfo;
#if ILMTHREAD_THREADING_ENABLED
Expand Down
4 changes: 3 additions & 1 deletion src/lib/OpenEXRCore/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,11 @@ exr_chunk_default_initialize (
if (box->min.y < dw.min.y || box->min.y > dw.max.y)
return EXR_ERR_INVALID_ARGUMENT;

if (ctxt->mode == EXR_CONTEXT_TEMPORARY)
if (ctxt->mode == EXR_CONTEXT_TEMPORARY && part->chunk_count < 0)
{
part->chunk_count = internal_exr_compute_chunk_offset_size (part);
if (part->chunk_count < 0)
return EXR_ERR_INVALID_ARGUMENT;
}

if (part->storage_mode == EXR_STORAGE_SCANLINE ||
Expand Down
6 changes: 6 additions & 0 deletions src/lib/OpenEXRCore/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ exr_write_header (exr_context_t ctxt)
if (rv != EXR_ERR_SUCCESS) break;

ccount = internal_exr_compute_chunk_offset_size (curp);
if (ccount < 0)
return EXR_UNLOCK_AND_RETURN (
ctxt->report_error (
ctxt,
EXR_ERR_FILE_BAD_HEADER,
"Invalid part specification computing number of chunks in file"));

curp->chunk_count = ccount;

Expand Down
1 change: 1 addition & 0 deletions src/lib/OpenEXRCore/internal_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ internal_exr_add_part (
part->display_window.max.x = -1;
part->display_window.max.y = -1;
part->chunk_count = -1;
part->lines_per_chunk = -1;

part->zip_compression_level = f->default_zip_level;
part->dwa_compression_level = f->default_dwa_quality;
Expand Down
5 changes: 3 additions & 2 deletions src/lib/OpenEXRCore/parse_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -2359,9 +2359,10 @@ internal_exr_compute_chunk_offset_size (exr_priv_part_t curpart)
int linePerChunk, h;

linePerChunk = exr_compression_lines_per_chunk (curpart->comp_type);
if (linePerChunk < 0) return -1;

curpart->lines_per_chunk = ((int16_t) linePerChunk);
curpart->lines_per_chunk = linePerChunk;

if (linePerChunk < 0) return -1;

for (int c = 0; c < channels->num_channels; ++c)
{
Expand Down

0 comments on commit ae646ec

Please sign in to comment.