]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[deflate] Fix literal data length calculation
authorMichael Brown <mcb30@ipxe.org>
Wed, 8 Jan 2014 22:21:23 +0000 (23:21 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sun, 12 Jan 2014 21:53:10 +0000 (22:53 +0100)
Fix incorrect calculation used to determine length of data to be
copied within a literal data block, and add a test case to prevent
this bug from going undetected in future.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/crypto/deflate.c
src/tests/deflate_test.c

index 1854eff436b5954036e463f102bc250abb923476..91a4899610c60bb9d4635dfb28d7a7a0d65c4f9e 100644 (file)
@@ -609,7 +609,7 @@ int deflate_inflate ( struct deflate *deflate,
                /* Calculate available amount of literal data */
                in_remaining = ( in->len - in->offset );
                len = deflate->remaining;
-               if ( len < in_remaining )
+               if ( len > in_remaining )
                        len = in_remaining;
 
                /* Copy data to output buffer */
index 1223492fadbbcc3c222bd1ba98defb0d788259f1..68c1aad961f73414365ae96703390e118324f2e0 100644 (file)
@@ -78,6 +78,12 @@ DEFLATE ( literal, DEFLATE_RAW,
          DATA ( 0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45 ),
          DATA ( 0x69, 0x50, 0x58, 0x45 ) );
 
+/* "iPXE" string, no compression, split into two literals */
+DEFLATE ( split_literal, DEFLATE_RAW,
+         DATA ( 0x00, 0x02, 0x00, 0xfd, 0xff, 0x69, 0x50, 0x01, 0x02, 0x00,
+                0xfd, 0xff, 0x58, 0x45 ),
+         DATA ( 0x69, 0x50, 0x58, 0x45 ) );
+
 /* Empty file */
 DEFLATE ( empty, DEFLATE_RAW, DATA ( 0x03, 0x00 ), DATA() );
 
@@ -215,6 +221,7 @@ static void deflate_test_exec ( void ) {
                /* Test as a single pass */
                deflate_ok ( deflate, &empty_literal, NULL );
                deflate_ok ( deflate, &literal, NULL );
+               deflate_ok ( deflate, &split_literal, NULL );
                deflate_ok ( deflate, &empty, NULL );
                deflate_ok ( deflate, &hello_world, NULL );
                deflate_ok ( deflate, &hello_hello_world, NULL );