1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

BCJ filters: Reject invalid start offsets with LZMA_OPTIONS_ERROR.

This is a quick and slightly dirty fix to make the code
conform to the latest file format specification. Without
this patch, it's possible to make corrupt files by
specifying start offset that is not a multiple of the
filter's alignment. Custom start offset is almost never
used, so this was only a minor bug.

The xz command line tool doesn't validate the start offset,
so one will get a bit unclear error message if trying to use
an invalid start offset.
This commit is contained in:
Lasse Collin 2009-07-10 11:39:38 +03:00
parent eed9953732
commit cd69a5a6c1
8 changed files with 12 additions and 8 deletions

View file

@ -49,7 +49,7 @@ arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
return lzma_simple_coder_init(next, allocator, filters, return lzma_simple_coder_init(next, allocator, filters,
&arm_code, 0, 4, is_encoder); &arm_code, 0, 4, 4, is_encoder);
} }

View file

@ -54,7 +54,7 @@ armthumb_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
return lzma_simple_coder_init(next, allocator, filters, return lzma_simple_coder_init(next, allocator, filters,
&armthumb_code, 0, 4, is_encoder); &armthumb_code, 0, 4, 2, is_encoder);
} }

View file

@ -90,7 +90,7 @@ ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
return lzma_simple_coder_init(next, allocator, filters, return lzma_simple_coder_init(next, allocator, filters,
&ia64_code, 0, 16, is_encoder); &ia64_code, 0, 16, 16, is_encoder);
} }

View file

@ -53,7 +53,7 @@ powerpc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
return lzma_simple_coder_init(next, allocator, filters, return lzma_simple_coder_init(next, allocator, filters,
&powerpc_code, 0, 4, is_encoder); &powerpc_code, 0, 4, 4, is_encoder);
} }

View file

@ -215,7 +215,8 @@ lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, const lzma_filter_info *filters,
size_t (*filter)(lzma_simple *simple, uint32_t now_pos, size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
bool is_encoder, uint8_t *buffer, size_t size), bool is_encoder, uint8_t *buffer, size_t size),
size_t simple_size, size_t unfiltered_max, bool is_encoder) size_t simple_size, size_t unfiltered_max,
uint32_t alignment, bool is_encoder)
{ {
// Allocate memory for the lzma_coder structure if needed. // Allocate memory for the lzma_coder structure if needed.
if (next->coder == NULL) { if (next->coder == NULL) {
@ -249,6 +250,8 @@ lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
if (filters[0].options != NULL) { if (filters[0].options != NULL) {
const lzma_options_bcj *simple = filters[0].options; const lzma_options_bcj *simple = filters[0].options;
next->coder->now_pos = simple->start_offset; next->coder->now_pos = simple->start_offset;
if (next->coder->now_pos & (alignment - 1))
return LZMA_OPTIONS_ERROR;
} else { } else {
next->coder->now_pos = 0; next->coder->now_pos = 0;
} }

View file

@ -70,6 +70,7 @@ extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
lzma_allocator *allocator, const lzma_filter_info *filters, lzma_allocator *allocator, const lzma_filter_info *filters,
size_t (*filter)(lzma_simple *simple, uint32_t now_pos, size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
bool is_encoder, uint8_t *buffer, size_t size), bool is_encoder, uint8_t *buffer, size_t size),
size_t simple_size, size_t unfiltered_max, bool is_encoder); size_t simple_size, size_t unfiltered_max,
uint32_t alignment, bool is_encoder);
#endif #endif

View file

@ -61,7 +61,7 @@ sparc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
return lzma_simple_coder_init(next, allocator, filters, return lzma_simple_coder_init(next, allocator, filters,
&sparc_code, 0, 4, is_encoder); &sparc_code, 0, 4, 4, is_encoder);
} }

View file

@ -127,7 +127,7 @@ x86_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
const lzma_filter_info *filters, bool is_encoder) const lzma_filter_info *filters, bool is_encoder)
{ {
const lzma_ret ret = lzma_simple_coder_init(next, allocator, filters, const lzma_ret ret = lzma_simple_coder_init(next, allocator, filters,
&x86_code, sizeof(lzma_simple), 5, is_encoder); &x86_code, sizeof(lzma_simple), 5, 1, is_encoder);
if (ret == LZMA_OK) { if (ret == LZMA_OK) {
next->coder->simple->prev_mask = 0; next->coder->simple->prev_mask = 0;