Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ avifResult avifRWStreamWriteBox(avifRWStream * stream, const char * type, size_t
avifResult avifRWStreamWriteFullBox(avifRWStream * stream, const char * type, size_t contentSize, int version, uint32_t flags, avifBoxMarker * marker);
// marker is the offset of the size field in stream, returned by a previous
// avifRWStreamWriteBox() or avifRWStreamWriteFullBox() call.
void avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker);
AVIF_NODISCARD avifResult avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can remove this AVIF_NODISCARD after this PR passes the CI workflows.

avifResult avifRWStreamWriteU8(avifRWStream * stream, uint8_t v);
avifResult avifRWStreamWriteU16(avifRWStream * stream, uint16_t v);
avifResult avifRWStreamWriteU32(avifRWStream * stream, uint32_t v);
Expand Down
9 changes: 4 additions & 5 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,19 @@ avifResult avifRWStreamWriteBox(avifRWStream * stream, const char * type, size_t
return avifRWStreamWriteFullBox(stream, type, contentSize, -1, 0, marker);
}

void avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker)
avifResult avifRWStreamFinishBox(avifRWStream * stream, avifBoxMarker marker)
{
assert(stream->numUsedBitsInPartialByte == 0); // Byte alignment is required.
size_t boxSize = stream->offset - marker;
// Since marker comes from a previous avifRWStreamWriteBox() or
// avifRWStreamWriteFullBox() call, boxSize must be >= the size of the size
// and type fields. This implies that boxSize cannot be equal to the two
// special values 0 and 1.
assert(boxSize >= sizeof(uint32_t) + 4);
if (boxSize > UINT32_MAX) {
abort();
}
AVIF_ASSERT_OR_RETURN(boxSize >= sizeof(uint32_t) + 4);
AVIF_CHECKERR(boxSize <= UINT32_MAX, AVIF_RESULT_INVALID_ARGUMENT);
uint32_t noSize = avifHTONL((uint32_t)boxSize);
memcpy(stream->raw->data + marker, &noSize, sizeof(uint32_t));
return AVIF_RESULT_OK;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please review. Only this file and the change at src/write.c:3480 (annotated with a comment) need to be checked carefully. All the other changes are mechanical changes. Thanks!

}

avifResult avifRWStreamWriteU8(avifRWStream * stream, uint8_t v)
Expand Down
Loading
Loading