Parcourir la 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 il y a 11 ans
Parent
révision
97fd5ccdd8
2 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 1
    1
      src/crypto/deflate.c
  2. 7
    0
      src/tests/deflate_test.c

+ 1
- 1
src/crypto/deflate.c Voir le fichier

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

+ 7
- 0
src/tests/deflate_test.c Voir le fichier

@@ -78,6 +78,12 @@ DEFLATE ( literal, DEFLATE_RAW,
78 78
 	  DATA ( 0x01, 0x04, 0x00, 0xfb, 0xff, 0x69, 0x50, 0x58, 0x45 ),
79 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 87
 /* Empty file */
82 88
 DEFLATE ( empty, DEFLATE_RAW, DATA ( 0x03, 0x00 ), DATA() );
83 89
 
@@ -215,6 +221,7 @@ static void deflate_test_exec ( void ) {
215 221
 		/* Test as a single pass */
216 222
 		deflate_ok ( deflate, &empty_literal, NULL );
217 223
 		deflate_ok ( deflate, &literal, NULL );
224
+		deflate_ok ( deflate, &split_literal, NULL );
218 225
 		deflate_ok ( deflate, &empty, NULL );
219 226
 		deflate_ok ( deflate, &hello_world, NULL );
220 227
 		deflate_ok ( deflate, &hello_hello_world, NULL );

Chargement…
Annuler
Enregistrer