-
Notifications
You must be signed in to change notification settings - Fork 254
Make image size limit configurable, expose to avifdec #527
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,10 @@ typedef int avifBool; | |
| #define AVIF_SPEED_SLOWEST 0 | ||
| #define AVIF_SPEED_FASTEST 10 | ||
|
|
||
| // A maximum image size to avoid out-of-memory errors or integer overflow in | ||
| // (32-bit) int or unsigned int arithmetic operations. | ||
| #define AVIF_MAX_IMAGE_SIZE (16384 * 16384) | ||
|
||
|
|
||
| enum avifPlanesFlags | ||
| { | ||
| AVIF_PLANES_YUV = (1 << 0), | ||
|
|
@@ -701,6 +705,11 @@ typedef struct avifDecoder | |
| avifBool ignoreExif; | ||
| avifBool ignoreXMP; | ||
|
|
||
| // This represents the maximum size of a image (in pixel count) that the underlying AV1 decoder | ||
|
||
| // should attempt to decode. It defaults to AVIF_MAX_IMAGE_SIZE, and can be set to 0 to disable | ||
| // the limit. Currently supported codecs: dav1d. | ||
|
||
| uint32_t imageSizeLimit; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We also need to make sure all of our multiplications involving width or height do not overflow the integer type used in the arithmetic. I remember I reviewed that before, but it is best to check it again.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about my confusion. I checked the wrong function. Bullet 1 should read:
Bullet 2 is correct. I was referring to the following code in avifParseImageGridBox():
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. That is a good question. Do we want
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imageSizeLimit serves two purposes:
|
||
|
|
||
| // stats from the most recent read, possibly 0s if reading an image sequence | ||
| avifIOStats ioStats; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ static avifBool dav1dCodecOpen(avifCodec * codec, avifDecoder * decoder) | |
| // Give all available threads to decode a single frame as fast as possible | ||
| codec->internal->dav1dSettings.n_frame_threads = 1; | ||
| codec->internal->dav1dSettings.n_tile_threads = AVIF_CLAMP(decoder->maxThreads, 1, DAV1D_MAX_TILE_THREADS); | ||
| codec->internal->dav1dSettings.frame_size_limit = decoder->imageSizeLimit; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add a comment to note that dav1d uses the same convention that 0 = unlimited, so this simple assignment is safe. Note: I found that dav1d/tools/dav1d_cli_parse.c disallows its --sizelimit argument to be exactly UINT_MAX: I don't know whether that is intentional or an off-by-one bug. |
||
|
|
||
| if (dav1d_open(&codec->internal->dav1dContext, &codec->internal->dav1dSettings) != 0) { | ||
| return AVIF_FALSE; | ||
|
|
@@ -209,9 +210,6 @@ avifCodec * avifCodecCreateDav1d(void) | |
| memset(codec->internal, 0, sizeof(struct avifCodecInternal)); | ||
| dav1d_default_settings(&codec->internal->dav1dSettings); | ||
|
|
||
| // Set a maximum frame size limit to avoid OOM'ing fuzzers. | ||
| codec->internal->dav1dSettings.frame_size_limit = AVIF_MAX_IMAGE_SIZE; | ||
|
|
||
| // Ensure that we only get the "highest spatial layer" as a single frame | ||
| // for each input sample, instead of getting each spatial layer as its own | ||
| // frame one at a time ("all layers"). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we should call this "The default maximum image size ..." now