Reorder the offset checks in avifIOTestReaderRead
Perform the offset checks in the same order as the comments for
avifIOReadFunc in avif.h.
diff --git a/tests/aviftest.c b/tests/aviftest.c
index 861f8e7..770dd6a 100644
--- a/tests/aviftest.c
+++ b/tests/aviftest.c
@@ -273,15 +273,15 @@
avifIOTestReader * reader = (avifIOTestReader *)io;
// Sanitize/clamp incoming request
+ if (offset > reader->rodata.size) {
+ // The offset is past the end of the buffer.
+ return AVIF_RESULT_IO_ERROR;
+ }
if (offset == reader->rodata.size) {
// The parser is *exactly* at EOF: return a 0-size pointer to any valid buffer
offset = 0;
size = 0;
}
- if (offset > reader->rodata.size) {
- // The offset is past the end of the buffer.
- return AVIF_RESULT_IO_ERROR;
- }
uint64_t availableSize = reader->rodata.size - offset;
if (size > availableSize) {
size = (size_t)availableSize;