Skip to content

Commit

Permalink
Check avifAlloc() in avifIOCreateMemoryReader()
Browse files Browse the repository at this point in the history
  • Loading branch information
y-guyon committed Oct 6, 2023
1 parent e2610c7 commit ee29bec
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,9 @@ typedef struct avifIO
void * data;
} avifIO;

// Returns NULL if the reader cannot be allocated.
AVIF_API avifIO * avifIOCreateMemoryReader(const uint8_t * data, size_t size);
// Returns NULL if the file cannot be opened or if the reader cannot be allocated.
AVIF_API avifIO * avifIOCreateFileReader(const char * filename);
AVIF_API void avifIODestroy(avifIO * io);

Expand Down
3 changes: 3 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ static void avifIOMemoryReaderDestroy(struct avifIO * io)
avifIO * avifIOCreateMemoryReader(const uint8_t * data, size_t size)
{
avifIOMemoryReader * reader = avifAlloc(sizeof(avifIOMemoryReader));
if (reader == NULL) {
return NULL;
}
memset(reader, 0, sizeof(avifIOMemoryReader));
reader->io.destroy = avifIOMemoryReaderDestroy;
reader->io.read = avifIOMemoryReaderRead;
Expand Down
2 changes: 1 addition & 1 deletion src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -3833,7 +3833,7 @@ void avifDecoderSetIO(avifDecoder * decoder, avifIO * io)
avifResult avifDecoderSetIOMemory(avifDecoder * decoder, const uint8_t * data, size_t size)
{
avifIO * io = avifIOCreateMemoryReader(data, size);
assert(io);
AVIF_CHECKERR(io != NULL, AVIF_RESULT_OUT_OF_MEMORY);
avifDecoderSetIO(decoder, io);
return AVIF_RESULT_OK;
}
Expand Down

0 comments on commit ee29bec

Please sign in to comment.