Skip to content

Commit ae90d15

Browse files
committed
fix mobi decompression recursion check (fixes #1316)
1 parent 5d43b04 commit ae90d15

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/MobiDoc.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ class HuffDicDecompressor {
203203

204204
u32 codeLength = 0;
205205

206-
Vec<u32> recursionGuard;
206+
int recursionDepth = 0;
207207

208208
public:
209209
HuffDicDecompressor();
@@ -237,15 +237,16 @@ bool HuffDicDecompressor::DecodeOne(u32 code, str::Str& dst) {
237237
}
238238

239239
if (!(symLen & 0x8000)) {
240-
if (recursionGuard.Contains(code)) {
240+
if (recursionDepth > 20) {
241241
logf("infinite recursion\n");
242242
return false;
243243
}
244-
recursionGuard.Append(code);
244+
recursionDepth++;
245245
if (!Decompress(p, symLen, dst)) {
246+
recursionDepth--;
246247
return false;
247248
}
248-
recursionGuard.Pop();
249+
recursionDepth--;
249250
} else {
250251
symLen &= 0x7fff;
251252
if (symLen > 127) {

0 commit comments

Comments
 (0)