Skip to content
Snippets Groups Projects
  • Scott Vokes's avatar
    06d4094c
    Fix possible state yielding MORE from finish(), but 0 bytes from poll(). · 06d4094c
    Scott Vokes authored
    If the decompression stream was terminated with a 1 bit at exactly the
    byte boundary (perhaps due to decompressing from flash memory and
    sinking erased 0xFF bytes until the end of a flash page), it could end
    up in a state where heatshrink_decoder_finish() would return
    HSDR_FINISH_MORE, but calling heatshrink_decoder_poll would always yield
    0 bytes of output. If _both_ results were not checked, this could lead to
    the code driving them uselessly calling them in a loop.
    
    Added regression test case:
    decoder_should_not_get_stuck_with_finish_yielding_MORE_but_0_bytes_output_from_poll
    
    Resolved by explicitly checking remaining input length in
    heatshrink_decoder_finish in the HSDS_YIELD_LITERAL state, since it is
    not safe to assume that the decompression stream input will be padded
    with 0 bits.
    06d4094c
    History
    Fix possible state yielding MORE from finish(), but 0 bytes from poll().
    Scott Vokes authored
    If the decompression stream was terminated with a 1 bit at exactly the
    byte boundary (perhaps due to decompressing from flash memory and
    sinking erased 0xFF bytes until the end of a flash page), it could end
    up in a state where heatshrink_decoder_finish() would return
    HSDR_FINISH_MORE, but calling heatshrink_decoder_poll would always yield
    0 bytes of output. If _both_ results were not checked, this could lead to
    the code driving them uselessly calling them in a loop.
    
    Added regression test case:
    decoder_should_not_get_stuck_with_finish_yielding_MORE_but_0_bytes_output_from_poll
    
    Resolved by explicitly checking remaining input length in
    heatshrink_decoder_finish in the HSDS_YIELD_LITERAL state, since it is
    not safe to assume that the decompression stream input will be padded
    with 0 bits.