Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/fstapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -5118,8 +5118,18 @@ int fstReaderIterBlocks2(fstReaderContext *ctx,
}
}

mem_required_for_traversal =
fstReaderUint64(xc->f) + 66; /* add in potential fastlz overhead */
{
uint64_t declared_traversal_len = fstReaderUint64(xc->f);

/* check for overflow */
if (declared_traversal_len >= (UINT64_MAX - 66)) {
goto block_err;
}

/* add in potential fastlz overhead */
mem_required_for_traversal = declared_traversal_len + 66;
}

/* extra null byte to catch any unterminated varint */
mem_for_traversal = (unsigned char *)calloc(1, mem_required_for_traversal + 1);
#ifdef FST_DEBUG
Expand Down
Binary file added tests/data/malformed/traversal_size_wraps.fst
Binary file not shown.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ malformed_cases = [
'time_chain_short',
'traversal_buffer_smaller_than_chain',
'traversal_buffer_smaller_than_chain_fastlz',
'traversal_size_wraps',
'uncompressed_chain_past_traversal',
'uncompressed_chain_shorter_than_its_varint',
'value_change_past_traversal',
Expand Down
4 changes: 4 additions & 0 deletions tests/reader_malformed_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
* nothing compared against the buffer. One file per decompressor: LZ4
* writes eight bytes at a time past the end, fastlz one
*
* traversal_size_wraps.fst
* the second of two value change sections declares a traversal size of
* 2**64 - 67
*
* uncompressed_chain_past_traversal.fst
* a value change section declaring it needs 7 bytes of memory to read,
* whose twenty handles share one uncompressed chain 19 bytes long and so
Expand Down
Loading