Skip to content

Commit 34b1be1

Browse files
committed
Fix #503 - did not get expected restart marker
1 parent b24a740 commit 34b1be1

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/pixie/fileformats/jpeg.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const
3939
0.uint32, 1, 3, 7, 15, 31, 63, 127, 255, 511,
4040
1023, 2047, 4095, 8191, 16383, 32767, 65535
4141
]
42+
jpegEndOfImage = 0xD9
4243

4344
type
4445
Huffman = object
@@ -876,7 +877,10 @@ proc checkRestart(state: var DecoderState) =
876877
dec state.todoBeforeRestart
877878
if state.todoBeforeRestart <= 0:
878879
if state.pos + 1 > state.len:
880+
echo $state
879881
failInvalid()
882+
if state.buffer[state.pos] == 0xFF and state.buffer[state.pos+1] == jpegEndOfImage:
883+
return
880884
if state.buffer[state.pos] != 0xFF or
881885
state.buffer[state.pos + 1] notin {0xD0 .. 0xD7}:
882886
failInvalid("did not get expected restart marker")

0 commit comments

Comments
 (0)