From c78e186739b50d156cb3da5d08d70294f0490853 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Sat, 18 Sep 2021 21:56:15 +0200 Subject: [PATCH] Fix potential out-of-buffer read while parsing corrupt file, closes #38 --- src/read.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/read.c b/src/read.c index 0d2d9e4..666987f 100644 --- a/src/read.c +++ b/src/read.c @@ -752,6 +752,10 @@ MOBI_RET mobi_parse_huffdic(const MOBIData *m, MOBIHuffCdic *huffcdic) { } curr = curr->next; } + if (huffcdic->index_count != huffcdic->index_read) { + debug_print("CDIC: wrong read index count: %zu, total: %zu\n", huffcdic->index_read, huffcdic->index_count); + return MOBI_DATA_CORRUPT; + } return MOBI_SUCCESS; }