mirror of
https://github.com/webmproject/libwebp.git
synced 2026-04-09 14:22:31 +02:00
mux,anim: ensure all images are in ANMF chunks
In an animated file, all image chunks must be contained in ANMF chunks. This fixes an assertion failure: ``` src/mux/muxedit.c:448 in WebPMuxError GetAdjustedCanvasSize(const WebPMux *const, int *const, int *const): wpi->header != NULL ``` The demux library already has this check. Bug: 498966755 Change-Id: I1f04088a60326b47d26d7690277192118ed8374f
This commit is contained in:
@@ -500,6 +500,14 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
|||||||
err = ValidateChunk(mux, IDX_XMP, XMP_FLAG, flags, 1, &num_xmp);
|
err = ValidateChunk(mux, IDX_XMP, XMP_FLAG, flags, 1, &num_xmp);
|
||||||
if (err != WEBP_MUX_OK) return err;
|
if (err != WEBP_MUX_OK) return err;
|
||||||
|
|
||||||
|
// Verify either VP8X chunk is present OR there is only one elem in
|
||||||
|
// mux->images.
|
||||||
|
err = ValidateChunk(mux, IDX_VP8X, NO_FLAG, flags, 1, &num_vp8x);
|
||||||
|
if (err != WEBP_MUX_OK) return err;
|
||||||
|
err = ValidateChunk(mux, IDX_VP8, NO_FLAG, flags, -1, &num_images);
|
||||||
|
if (err != WEBP_MUX_OK) return err;
|
||||||
|
if (num_vp8x == 0 && num_images != 1) return WEBP_MUX_INVALID_ARGUMENT;
|
||||||
|
|
||||||
// Animation: ANIMATION_FLAG, ANIM chunk and ANMF chunk(s) are consistent.
|
// Animation: ANIMATION_FLAG, ANIM chunk and ANMF chunk(s) are consistent.
|
||||||
// At most one ANIM chunk.
|
// At most one ANIM chunk.
|
||||||
err = ValidateChunk(mux, IDX_ANIM, NO_FLAG, flags, 1, &num_anim);
|
err = ValidateChunk(mux, IDX_ANIM, NO_FLAG, flags, 1, &num_anim);
|
||||||
@@ -509,7 +517,10 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const int has_animation = !!(flags & ANIMATION_FLAG);
|
const int has_animation = !!(flags & ANIMATION_FLAG);
|
||||||
if (has_animation && (num_anim == 0 || num_frames == 0)) {
|
// An ANIM chunk must be present when has_animation is true, and all images
|
||||||
|
// must be contained in ANMF chunks.
|
||||||
|
if (has_animation &&
|
||||||
|
(num_anim == 0 || num_frames == 0 || num_frames != num_images)) {
|
||||||
return WEBP_MUX_INVALID_ARGUMENT;
|
return WEBP_MUX_INVALID_ARGUMENT;
|
||||||
}
|
}
|
||||||
if (!has_animation && (num_anim == 1 || num_frames > 0)) {
|
if (!has_animation && (num_anim == 1 || num_frames > 0)) {
|
||||||
@@ -531,14 +542,6 @@ WebPMuxError MuxValidate(const WebPMux* const mux) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify either VP8X chunk is present OR there is only one elem in
|
|
||||||
// mux->images.
|
|
||||||
err = ValidateChunk(mux, IDX_VP8X, NO_FLAG, flags, 1, &num_vp8x);
|
|
||||||
if (err != WEBP_MUX_OK) return err;
|
|
||||||
err = ValidateChunk(mux, IDX_VP8, NO_FLAG, flags, -1, &num_images);
|
|
||||||
if (err != WEBP_MUX_OK) return err;
|
|
||||||
if (num_vp8x == 0 && num_images != 1) return WEBP_MUX_INVALID_ARGUMENT;
|
|
||||||
|
|
||||||
// ALPHA_FLAG & alpha chunk(s) are consistent.
|
// ALPHA_FLAG & alpha chunk(s) are consistent.
|
||||||
// Note: ALPHA_FLAG can be set when there is actually no Alpha data present.
|
// Note: ALPHA_FLAG can be set when there is actually no Alpha data present.
|
||||||
if (MuxHasAlpha(mux->images)) {
|
if (MuxHasAlpha(mux->images)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user