obudec: Avoid problems when near buf capacity.
Double the size of the buffer instead of using the current OBU payload
size when running out of space. Avoids the situation described in
aomedia:2162. Also adds roll over check on new buffer size.
BUG=aomedia:2162
Change-Id: I7be7338598be34a70334085cbb894ef95596949e
diff --git a/common/obudec.c b/common/obudec.c
index acbd12e..e2057bf 100644
--- a/common/obudec.c
+++ b/common/obudec.c
@@ -200,9 +200,11 @@
}
if (bytes_read + obu_payload_length > available_buffer_capacity) {
- // TODO(tomfinegan): Add overflow check.
- const size_t new_capacity =
- obu_bytes_buffered + bytes_read + 2 * obu_payload_length;
+ if (*obu_buffer_capacity >= (SIZE_MAX >> 1)) {
+ fprintf(stderr, "obudec: cannot realloc buffer; capacity rolled over.\n");
+ return -1;
+ }
+ const size_t new_capacity = 2 * *obu_buffer_capacity;
#if defined AOM_MAX_ALLOCABLE_MEMORY
if (new_capacity > AOM_MAX_ALLOCABLE_MEMORY) {