Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrain XMP,Exif size in avifJPEGReadInternal() #2045

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

y-guyon
Copy link
Collaborator

@y-guyon y-guyon commented Feb 29, 2024

if (found) {
// TODO(yguyon): Implement instead of outputting an error.
fprintf(stderr, "Exif extraction failed: unsupported Exif split into multiple segments or invalid multiple Exif segments\n");
goto cleanup;
}

if (marker->data_length - AVIF_JPEG_EXIF_HEADER_LENGTH > imageSizeLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know there is a condition above but in case the code gets moved one day, maybe it is safer (overflow/type change-wise) to write: marker->data_length > AVIF_JPEG_EXIF_HEADER_LENGTH + imageSizeLimit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

imageSizeLimit could be MAX_UINT

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are using imageSizeLimit for a different purpose: the maximum Exif or XMP metadata size.

Would it be better to impose our own maximum Exif and XMP metadata sizes? For example, we can use a small multiple of 64 KB. See

https://stackoverflow.com/questions/3248946/what-is-the-maximum-size-of-jpeg-metadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed imageSizeLimit in #2047

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be better to impose our own maximum Exif and XMP metadata sizes? For example, we can use a small multiple of 64 KB. See

I do not think it is worth it until there is a use case or user complaint for that.

@y-guyon y-guyon merged commit 8db5d51 into AOMediaCodec:main Feb 29, 2024
19 checks passed
@y-guyon y-guyon deleted the avifjpeg_xmp branch February 29, 2024 15:03
@@ -1062,8 +1073,13 @@ static avifBool avifJPEGReadInternal(FILE * f,
// "offset of this portion as a 32-bit unsigned integer"
const uint32_t extendedXMPOffset = avifJPEGReadUint32BigEndian(
&marker->data[AVIF_JPEG_EXTENDED_XMP_TAG_LENGTH + AVIF_JPEG_EXTENDED_XMP_GUID_LENGTH + 4]);
if (((uint64_t)standardXMPSize + totalExtendedXMPSize) > SIZE_MAX) {
fprintf(stderr, "XMP extraction failed: total XMP size is too large\n");
if (((uint64_t)standardXMPSize + totalExtendedXMPSize) > imageSizeLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the original code, this check compares the sum with SIZE_MAX. I believe it was intended to check if it would be safe to cast the sum to size_t in line 1101 below.

In the new code, this check is stricter, so the size_t cast is still safe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: It may be good to add an assertion here:

    assert(imageSizeLimit <= SIZE_MAX);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Optional: It may be good to add an assertion here:

    assert(imageSizeLimit <= SIZE_MAX);

My IDE CLion shows the following warning:

Result of comparison of constant 18446744073709551615 with expression of type 'uint32_t' (aka 'unsigned int') is always true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Kept the old condition in #2047 instead

if (found) {
// TODO(yguyon): Implement instead of outputting an error.
fprintf(stderr, "Exif extraction failed: unsupported Exif split into multiple segments or invalid multiple Exif segments\n");
goto cleanup;
}

if (marker->data_length - AVIF_JPEG_EXIF_HEADER_LENGTH > imageSizeLimit) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are using imageSizeLimit for a different purpose: the maximum Exif or XMP metadata size.

Would it be better to impose our own maximum Exif and XMP metadata sizes? For example, we can use a small multiple of 64 KB. See

https://stackoverflow.com/questions/3248946/what-is-the-maximum-size-of-jpeg-metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants