node-lz4 icon indicating copy to clipboard operation
node-lz4 copied to clipboard

Invalid block checksum

Open alexfernandez opened this issue 6 years ago • 0 comments

After compressing a block and decompressing it with blockChecksum enabled, node-lz4 bombs:

    const decoder = lz4.createDecoderStream({
      });
      const encoder = lz4.createEncoderStream({ 
        blockChecksum: true,
        //debug: true,
      })
      const buffers = []
      encoder.on('data', data => decoder.write(data))
      encoder.on('end', () => decoder.end())
      decoder.on('data', data => buffers.push(data))
      decoder.on('end', () => {
        console.log('Received %s', Buffer.concat(buffers))
      })
      encoder.end('panchi pinchi pinchi panchi punchi\n')

results in:

Invalid block checksum: 3942400633 vs 3364695891 for {"type":"Buffer","data":[153,112,97,110,99,104,105,32,112,105,7,0,3,21,0,96,117,110,99,104,105,10]} @26

After investigating in the guts of lib/encoder_stream.js here it appears that it computes the checksum on a buffer that contains the compressed block, and some padding: instead of only 9970616e636869207069070003150060756e6368690a it hashes 9970616e636869207069070003150060756e6368690a0000000000000000000000000000000000000000000000000000000000, which yields the error.

alexfernandez avatar Dec 15 '17 17:12 alexfernandez