mirror of
https://git.tukaani.org/xz.git
synced 2026-10-31 19:34:55 +00:00
liblzma: Index decoder: Detect a too large allocation earlier
Previously, if an Index had more than PREALLOC_MAX Records, then allocations were done in PREALLOC_DEFAULT chunks (512 Records). That makes little sense in practice because it's likely that one would run out of address space later. Return LZMA_MEM_ERROR error pre-emptively if PREALLOC_MAX would be exceeded.
This commit is contained in:
parent
9be8d5c91f
commit
a967036afb
@ -427,11 +427,11 @@ lzma_index_end(lzma_index *i, const lzma_allocator *allocator)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void
|
extern bool
|
||||||
lzma_index_prealloc(lzma_index *i, lzma_vli records)
|
lzma_index_prealloc(lzma_index *i, lzma_vli records)
|
||||||
{
|
{
|
||||||
if (records > PREALLOC_MAX)
|
if (records > PREALLOC_MAX)
|
||||||
records = PREALLOC_MAX;
|
return true;
|
||||||
|
|
||||||
// If index_decoder.c calls us with records == 0, it's decoding
|
// If index_decoder.c calls us with records == 0, it's decoding
|
||||||
// an Index that has no Records. In that case the decoder won't call
|
// an Index that has no Records. In that case the decoder won't call
|
||||||
@ -454,7 +454,7 @@ lzma_index_prealloc(lzma_index *i, lzma_vli records)
|
|||||||
records = INDEX_GROUP_SIZE;
|
records = INDEX_GROUP_SIZE;
|
||||||
|
|
||||||
i->prealloc = (size_t)(records);
|
i->prealloc = (size_t)(records);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -38,7 +38,9 @@ extern uint32_t lzma_index_padding_size(const lzma_index *i);
|
|||||||
/// Set for how many Records to allocate memory the next time
|
/// Set for how many Records to allocate memory the next time
|
||||||
/// lzma_index_append() needs to allocate space for a new Record.
|
/// lzma_index_append() needs to allocate space for a new Record.
|
||||||
/// This is used only by the Index decoder.
|
/// This is used only by the Index decoder.
|
||||||
extern void lzma_index_prealloc(lzma_index *i, lzma_vli records);
|
///
|
||||||
|
/// \return false on success, true if records is too large (SIZE_MAX issue)
|
||||||
|
extern bool lzma_index_prealloc(lzma_index *i, lzma_vli records);
|
||||||
|
|
||||||
|
|
||||||
/// Round the variable-length integer to the next multiple of four.
|
/// Round the variable-length integer to the next multiple of four.
|
||||||
|
|||||||
@ -123,7 +123,10 @@ index_decode(void *coder_ptr, const lzma_allocator *allocator,
|
|||||||
|
|
||||||
// Tell the Index handling code how many Records this
|
// Tell the Index handling code how many Records this
|
||||||
// Index has to allow it to allocate memory more efficiently.
|
// Index has to allow it to allocate memory more efficiently.
|
||||||
lzma_index_prealloc(coder->index, coder->count);
|
// If the Record count is so high that memory allocation would
|
||||||
|
// fail later, return LZMA_MEM_ERROR now.
|
||||||
|
if (lzma_index_prealloc(coder->index, coder->count))
|
||||||
|
return LZMA_MEM_ERROR;
|
||||||
|
|
||||||
ret = LZMA_OK;
|
ret = LZMA_OK;
|
||||||
coder->sequence = coder->count == 0
|
coder->sequence = coder->count == 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user