This commit is contained in:
Ryan Oldenburg 2022-05-25 19:57:47 -05:00
parent 75f630f824
commit b360b68fe8

View file

@ -842,14 +842,12 @@ proc checkRestart(state: var DecoderState) =
## Check if we might have run into a restart marker, then deal with it. ## Check if we might have run into a restart marker, then deal with it.
dec state.todoBeforeRestart dec state.todoBeforeRestart
if state.todoBeforeRestart <= 0: if state.todoBeforeRestart <= 0:
if state.bitsBuffered < 24: if state.pos + 1 > state.len:
state.fillBitBuffer() failInvalid()
if state.buffer[state.pos] != 0xFF or
if state.buffer[state.pos] == 0xFF: state.buffer[state.pos + 1] notin {0xD0 .. 0xD7}:
if state.buffer[state.pos + 1] in {0xD0 .. 0xD7}: failInvalid("did not get expected restart marker")
state.pos += 2 state.pos += 2
else:
failInvalid("did not get expected restart marker")
state.reset() state.reset()
proc decodeBlocks(state: var DecoderState) = proc decodeBlocks(state: var DecoderState) =