Skip to content

Commit 2ed2db5

Browse files
committed
compress: Prevent call stack overflow
Explicitly use goto to turn a recursive call into an iterative one. Most compilers do this on their own with default settings, but MSVC with default settings would create a binary which actually performs recursive calls. Fixes call stack overflow in binaries compiled with low optimization. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
1 parent 59b0979 commit 2ed2db5

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

libarchive/archive_read_support_filter_compress.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ next_code(struct archive_read_filter *self)
328328
static int debug_buff[1024];
329329
static unsigned debug_index;
330330

331+
again:
331332
code = newcode = getbits(self, state->bits);
332333
if (code < 0)
333334
return (code);
@@ -360,7 +361,7 @@ next_code(struct archive_read_filter *self)
360361
state->section_end_code = (1 << state->bits) - 1;
361362
state->free_ent = 257;
362363
state->oldcode = -1;
363-
return (next_code(self));
364+
goto again;
364365
}
365366

366367
if (code > state->free_ent

0 commit comments

Comments
 (0)