intel / intel/isa-l

Maybe a bug in isal_inflate_stateless()

Open
#405 11 comments 0 reactions 0 assignees View on GitHub
sighting
Dominant language
C
Stars
1.1k
Forks
346
PR merge metrics
No merged PRs in 30d

Description

The loop at 2179 in isal_inflate_stateless() exits when decode_literal_block() returns 1 (end of input), which causes the CRC check to be skipped and the function to return 1 despite the decoding going well.

I think that loop runs one too many times. My compressed buffer is 515 bytes, and the uncompressed data is 1024 bytes.

The initial call to decode_huffman_code_block_stateless() consumes the entire input and emits the entire output and returns 0.

avail_in = 0 and total_out = 1024 after decode_huffman_code_block_stateless() returns, but block_state is not set to ISAL_BLOCK_INPUT_DONE (it's left to ISAL_BLOCK_NEW_HDR) therefore the loop loops and calls read_hdr() which succeeds and ends up calling decode_literal_block() as block_state is now ISAL_BLOCK_TYPE0.

The loop must exit after decode_huffman_code_block_stateless() has consumed all the input bytes. Perhaps that function should set the block state to ISAL_BLOCK_INPUT_DONE?

As a quickfix, I changed lines 2192-93 from

if (ret)
break;

to

if (ret || !state->avail_in)
break;

where the reasoning is "if stateless (implicit in this function) and no more input" -> done.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.