Skip to content

Maybe a bug in isal_inflate_stateless() #405

Description

@axelriet

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions