Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,9 +1534,15 @@ static avifResult avifDecoderItemRead(avifDecoderItem * item,
item->mergedExtents.size = bytesToRead;
} else {
AVIF_ASSERT_OR_RETURN(item->ownsMergedExtents);
AVIF_ASSERT_OR_RETURN(front);
memcpy(front, offsetBuffer.data, bytesToRead);
front += bytesToRead;

size_t writeOffset = (size_t)(front - item->mergedExtents.data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the checks / assertions you are adding, the writeOffset variable is more convenient than the front variable.

I suggest replacing the front variable with the writeOffset variable. Then in the memcpy() call below, recover front by using item->mergedExtents.data + writeOffset.


AVIF_ASSERT_OR_RETURN(writeOffset < item->mergedExtents.size);
AVIF_ASSERT_OR_RETURN(bytesToRead <= item->mergedExtents.size - writeOffset);

uint8_t *dst = item->mergedExtents.data + writeOffset;
memcpy(dst, offsetBuffer.data, bytesToRead);
writeOffset += bytesToRead;
}

remainingBytes -= bytesToRead;
Expand Down
Loading