Browse Source

[deflate] Fix literal data length calculation

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>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
97fd5ccdd8
2 changed files with 8 additions and 1 deletions
  1. 1
    1
      src/crypto/deflate.c
  2. 7
    0
      src/tests/deflate_test.c

+ 1
- 1
src/crypto/deflate.c View File

609
 		/* Calculate available amount of literal data */
609
 		/* Calculate available amount of literal data */
610
 		in_remaining = ( in->len - in->offset );
610
 		in_remaining = ( in->len - in->offset );
611
 		len = deflate->remaining;
611
 		len = deflate->remaining;
612
-		if ( len < in_remaining )
612
+		if ( len > in_remaining )
613
 			len = in_remaining;
613
 			len = in_remaining;
614
 
614
 
615
 		/* Copy data to output buffer */
615
 		/* Copy data to output buffer */

+ 7
- 0
src/tests/deflate_test.c View File

78
 	  DATA ( 0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45 ),
78
 	  DATA ( 0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45 ),
79
 	  DATA ( 0x69, 0x50, 0x58, 0x45 ) );
79
 	  DATA ( 0x69, 0x50, 0x58, 0x45 ) );
80
 
80
 
81
+/* "iPXE" string, no compression, split into two literals */
82
+DEFLATE ( split_literal, DEFLATE_RAW,
83
+	  DATA ( 0x00, 0x02, 0x00, 0xfd, 0xff, 0x69, 0x50, 0x01, 0x02, 0x00,
84
+		 0xfd, 0xff, 0x58, 0x45 ),
85
+	  DATA ( 0x69, 0x50, 0x58, 0x45 ) );
86
+
81
 /* Empty file */
87
 /* Empty file */
82
 DEFLATE ( empty, DEFLATE_RAW, DATA ( 0x03, 0x00 ), DATA() );
88
 DEFLATE ( empty, DEFLATE_RAW, DATA ( 0x03, 0x00 ), DATA() );
83
 
89
 
215
 		/* Test as a single pass */
221
 		/* Test as a single pass */
216
 		deflate_ok ( deflate, &empty_literal, NULL );
222
 		deflate_ok ( deflate, &empty_literal, NULL );
217
 		deflate_ok ( deflate, &literal, NULL );
223
 		deflate_ok ( deflate, &literal, NULL );
224
+		deflate_ok ( deflate, &split_literal, NULL );
218
 		deflate_ok ( deflate, &empty, NULL );
225
 		deflate_ok ( deflate, &empty, NULL );
219
 		deflate_ok ( deflate, &hello_world, NULL );
226
 		deflate_ok ( deflate, &hello_world, NULL );
220
 		deflate_ok ( deflate, &hello_hello_world, NULL );
227
 		deflate_ok ( deflate, &hello_hello_world, NULL );

Loading…
Cancel
Save