inikep / lizard

Lizard (formerly LZ5) is an efficient compressor with very fast decompression. It achieves compression ratio that is comparable to zip/zlib and zstd/brotli (at low and medium compression levels) at decompression speed of 1000 MB/s and faster.
Other
652 stars 40 forks source link

Question about literal length decode #32

Closed akatsuki105 closed 3 years ago

akatsuki105 commented 3 years ago

In this document, extra length of literals should be read from Lengths_Stream, but if we look at source code, extra length seems to be read from Literals_Stream.

Is this correct specification?

        /* get literal length */
        token = *ctx->flagsPtr++;
        if ((length=(token & RUN_MASK_LZ4)) == RUN_MASK_LZ4) {
            if (unlikely(ctx->literalsPtr > iend - 5)) { LIZARD_LOG_DECOMPRESS_LZ4("0"); goto _output_error; } 
            length = *ctx->literalsPtr;
            if unlikely(length >= 254) {
                if (length == 254) {
                    length = MEM_readLE16(ctx->literalsPtr+1);
                    ctx->literalsPtr += 2;
                } else {
                    length = MEM_readLE24(ctx->literalsPtr+1);
                    ctx->literalsPtr += 3;
                }
            }
            length += RUN_MASK_LZ4;
            ctx->literalsPtr++;
            if (unlikely((size_t)(op+length)<(size_t)(op))) { LIZARD_LOG_DECOMPRESS_LZ4("1"); goto _output_error; }  /* overflow detection */
            if (unlikely((size_t)(ctx->literalsPtr+length)<(size_t)(ctx->literalsPtr))) { LIZARD_LOG_DECOMPRESS_LZ4("2"); goto _output_error; }   /* overflow detection */
        }