|
|
ca9047 |
diff --git a/src/mux/muxi.h b/src/mux/muxi.h
|
|
|
ca9047 |
index 6b57eea..14fd6e2 100644
|
|
|
ca9047 |
--- a/src/mux/muxi.h
|
|
|
ca9047 |
+++ b/src/mux/muxi.h
|
|
|
ca9047 |
|
|
|
ca9047 |
@@ -14,6 +14,7 @@
|
|
|
ca9047 |
#ifndef WEBP_MUX_MUXI_H_
|
|
|
ca9047 |
#define WEBP_MUX_MUXI_H_
|
|
|
ca9047 |
|
|
|
ca9047 |
+#include <assert.h>
|
|
|
ca9047 |
#include <stdlib.h>
|
|
|
ca9047 |
#include "src/dec/vp8i_dec.h"
|
|
|
ca9047 |
#include "src/dec/vp8li_dec.h"
|
|
|
ca9047 |
@@ -143,13 +144,13 @@
|
|
|
ca9047 |
|
|
|
ca9047 |
// Returns size of the chunk including chunk header and padding byte (if any).
|
|
|
ca9047 |
static WEBP_INLINE size_t SizeWithPadding(size_t chunk_size) {
|
|
|
ca9047 |
+ assert(chunk_size <= MAX_CHUNK_PAYLOAD);
|
|
|
ca9047 |
return CHUNK_HEADER_SIZE + ((chunk_size + 1) & ~1U);
|
|
|
ca9047 |
}
|
|
|
ca9047 |
|
|
|
ca9047 |
// Size of a chunk including header and padding.
|
|
|
ca9047 |
static WEBP_INLINE size_t ChunkDiskSize(const WebPChunk* chunk) {
|
|
|
ca9047 |
const size_t data_size = chunk->data_.size;
|
|
|
ca9047 |
- assert(data_size < MAX_CHUNK_PAYLOAD);
|
|
|
ca9047 |
return SizeWithPadding(data_size);
|
|
|
ca9047 |
}
|
|
|
ca9047 |
|
|
|
ca9047 |
|
|
|
ca9047 |
diff --git a/src/mux/muxread.c b/src/mux/muxread.c
|
|
|
ca9047 |
index eb5070b..ef50dae 100644
|
|
|
ca9047 |
--- a/src/mux/muxread.c
|
|
|
ca9047 |
+++ b/src/mux/muxread.c
|
|
|
ca9047 |
|
|
|
ca9047 |
@@ -59,6 +59,7 @@
|
|
|
ca9047 |
// Sanity checks.
|
|
|
ca9047 |
if (data_size < CHUNK_HEADER_SIZE) return WEBP_MUX_NOT_ENOUGH_DATA;
|
|
|
ca9047 |
chunk_size = GetLE32(data + TAG_SIZE);
|
|
|
ca9047 |
+ if (chunk_size > MAX_CHUNK_PAYLOAD) return WEBP_MUX_BAD_DATA;
|
|
|
ca9047 |
|
|
|
ca9047 |
{
|
|
|
ca9047 |
const size_t chunk_disk_size = SizeWithPadding(chunk_size);
|
|
|
ca9047 |
@@ -203,9 +204,14 @@
|
|
|
ca9047 |
goto Err; // First chunk should be VP8, VP8L or VP8X.
|
|
|
ca9047 |
}
|
|
|
ca9047 |
|
|
|
ca9047 |
- riff_size = SizeWithPadding(GetLE32(data + TAG_SIZE));
|
|
|
ca9047 |
+ riff_size = GetLE32(data + TAG_SIZE);
|
|
|
ca9047 |
+ if (riff_size > MAX_CHUNK_PAYLOAD) goto Err;
|
|
|
ca9047 |
+
|
|
|
ca9047 |
+ // Note this padding is historical and differs from demux.c which does not
|
|
|
ca9047 |
+ // pad the file size.
|
|
|
ca9047 |
+ riff_size = SizeWithPadding(riff_size);
|
|
|
ca9047 |
if (riff_size < CHUNK_HEADER_SIZE) goto Err;
|
|
|
ca9047 |
- if (riff_size > MAX_CHUNK_PAYLOAD || riff_size > size) goto Err;
|
|
|
ca9047 |
+ if (riff_size > size) goto Err;
|
|
|
ca9047 |
// There's no point in reading past the end of the RIFF chunk.
|
|
|
ca9047 |
if (size > riff_size + CHUNK_HEADER_SIZE) {
|
|
|
ca9047 |
size = riff_size + CHUNK_HEADER_SIZE;
|
|
|
ca9047 |
|
|
|
ca9047 |
|