]> granicus.if.org Git - xz/commitdiff
BCJ filters: Reject invalid start offsets with LZMA_OPTIONS_ERROR.
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 10 Jul 2009 08:39:38 +0000 (11:39 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 10 Jul 2009 08:39:38 +0000 (11:39 +0300)
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.

src/liblzma/simple/arm.c
src/liblzma/simple/armthumb.c
src/liblzma/simple/ia64.c
src/liblzma/simple/powerpc.c
src/liblzma/simple/simple_coder.c
src/liblzma/simple/simple_private.h
src/liblzma/simple/sparc.c
src/liblzma/simple/x86.c

index 46960fc83dcd4a01f9cd96c52e36fec39374117d..8fcf64374914617fe8d516deb74be5d71fec1bbc 100644 (file)
@@ -49,7 +49,7 @@ arm_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters, bool is_encoder)
 {
        return lzma_simple_coder_init(next, allocator, filters,
-                       &arm_code, 0, 4, is_encoder);
+                       &arm_code, 0, 4, 4, is_encoder);
 }
 
 
index e20151cc05a265611e859a094b4770417d3113f9..eb6a69d1282a08e2b0652857891b57557a877af5 100644 (file)
@@ -54,7 +54,7 @@ armthumb_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters, bool is_encoder)
 {
        return lzma_simple_coder_init(next, allocator, filters,
-                       &armthumb_code, 0, 4, is_encoder);
+                       &armthumb_code, 0, 4, 2, is_encoder);
 }
 
 
index 60247b32c2a039b0ffa62decab6741d1dfd09ed1..fd263d4aea0d844bda62b3fd42efa8c16bfe5dff 100644 (file)
@@ -90,7 +90,7 @@ ia64_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters, bool is_encoder)
 {
        return lzma_simple_coder_init(next, allocator, filters,
-                       &ia64_code, 0, 16, is_encoder);
+                       &ia64_code, 0, 16, 16, is_encoder);
 }
 
 
index 7ae734c93fc1bce67f1a597ac9433acc80c9d2e4..aaa14f22197715f4ad863036950d11e5ada8301d 100644 (file)
@@ -53,7 +53,7 @@ powerpc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters, bool is_encoder)
 {
        return lzma_simple_coder_init(next, allocator, filters,
-                       &powerpc_code, 0, 4, is_encoder);
+                       &powerpc_code, 0, 4, 4, is_encoder);
 }
 
 
index d44d632b80f33c5ce9b14ce4913bcc6299b23c31..497949a3d0933b05f5d4bda116a1741b4cac7844 100644 (file)
@@ -215,7 +215,8 @@ lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters,
                size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
                        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.
        if (next->coder == NULL) {
@@ -249,6 +250,8 @@ lzma_simple_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
        if (filters[0].options != NULL) {
                const lzma_options_bcj *simple = filters[0].options;
                next->coder->now_pos = simple->start_offset;
+               if (next->coder->now_pos & (alignment - 1))
+                       return LZMA_OPTIONS_ERROR;
        } else {
                next->coder->now_pos = 0;
        }
index 7571ae218dcf92e42fdd53e05ed9fc2cb18e5998..a69f82785fba66a042d368fadd475e8e6d8ccc3e 100644 (file)
@@ -70,6 +70,7 @@ extern lzma_ret lzma_simple_coder_init(lzma_next_coder *next,
                lzma_allocator *allocator, const lzma_filter_info *filters,
                size_t (*filter)(lzma_simple *simple, uint32_t now_pos,
                        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
index 04d428297071a15e8a911dec43059f1198f6b0b5..808a59aaac78cf54c2dec4f68b3486b4b0722745 100644 (file)
@@ -61,7 +61,7 @@ sparc_coder_init(lzma_next_coder *next, lzma_allocator *allocator,
                const lzma_filter_info *filters, bool is_encoder)
 {
        return lzma_simple_coder_init(next, allocator, filters,
-                       &sparc_code, 0, 4, is_encoder);
+                       &sparc_code, 0, 4, 4, is_encoder);
 }
 
 
index 425eae9ae239219c7ac236cabcda12cc5378f5f7..5d1509bb227807497ce34afe797bd5bb8faae9b5 100644 (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_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) {
                next->coder->simple->prev_mask = 0;