@@ -16,7 +16,6 @@ class TrailingChecksumTransform extends Transform {
1616 this . log = log ;
1717 this . errCb = errCb ;
1818 this . chunkSizeBuffer = Buffer . alloc ( 0 ) ;
19- this . outputBuffer = [ ] ;
2019 this . bytesToDiscard = 0 ; // when trailing \r\n are present, we discard them but they can be in different chunks
2120 this . bytesToRead = 0 ; // when a chunk is advertised, the size is put here and we forward all bytes
2221 this . streamClosed = false ;
@@ -42,7 +41,7 @@ class TrailingChecksumTransform extends Transform {
4241 // forward up to bytesToRead bytes from the chunk, restart processing on leftover
4342 if ( this . bytesToRead > 0 ) {
4443 const toRead = Math . min ( this . bytesToRead , chunk . byteLength ) ;
45- this . outputBuffer . push ( chunk . subarray ( 0 , toRead ) ) ;
44+ this . push ( chunk . subarray ( 0 , toRead ) ) ;
4645 chunk = chunk . subarray ( toRead ) ;
4746 this . bytesToRead -= toRead ;
4847 if ( this . bytesToRead === 0 ) {
@@ -64,13 +63,19 @@ class TrailingChecksumTransform extends Transform {
6463 }
6564 // no delimiter, we'll keep the chunk for later
6665 this . chunkSizeBuffer = Buffer . concat ( [ this . chunkSizeBuffer , chunk ] ) ;
67- break ;
66+ return callback ( ) ;
6867 }
6968
7069 this . chunkSizeBuffer = Buffer . concat ( [ this . chunkSizeBuffer , chunk . subarray ( 0 , lineBreakIndex2 ) ] ) ;
7170 chunk = chunk . subarray ( lineBreakIndex2 ) ;
7271
7372 // chunk-size is sent in hex
73+ if ( ! / ^ [ 0 - 9 a - f A - F ] + $ / . test ( this . chunkSizeBuffer . toString ( ) ) ) {
74+ this . log . debug ( 'chunk size is not a valid hex number' , {
75+ chunkSizeBuffer : this . chunkSizeBuffer . toString ( 'hex' ) ,
76+ } ) ;
77+ return callback ( errors . InvalidArgument ) ;
78+ }
7479 const dataSize = Number . parseInt ( this . chunkSizeBuffer . toString ( ) , 16 ) ;
7580 if ( Number . isNaN ( dataSize ) ) {
7681 this . log . debug ( 'unable to parse chunk size' , {
@@ -88,10 +93,7 @@ class TrailingChecksumTransform extends Transform {
8893 this . bytesToDiscard = 2 ;
8994 }
9095
91- // TODO: push the stream into a checksum accumulator
92- const toFlush = Buffer . concat ( this . outputBuffer ) ;
93- this . outputBuffer = [ ] ;
94- return callback ( null , toFlush , encoding ) ;
96+ return callback ( ) ;
9597 }
9698}
9799
0 commit comments