Merge pull request #517 from bung87/fix-int-set

fix int set
This commit is contained in:
Andre von Houck 2022-12-17 18:54:06 -08:00 committed by GitHub
commit cc68309225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View file

@ -297,8 +297,9 @@ proc decodeSOF0(state: var DecoderState) =
if state.imageWidth == 0: if state.imageWidth == 0:
failInvalid("image invalid 0 width") failInvalid("image invalid 0 width")
let numComponents = state.readUint8().int let numComponentsU8 = state.readUint8()
if numComponents notin {1, 3}: let numComponents = numComponentsU8.int
if numComponentsU8 notin {1'u8, 3}:
failInvalid("unsupported component count, must be 1 or 3") failInvalid("unsupported component count, must be 1 or 3")
len -= 6 len -= 6
@ -315,7 +316,7 @@ proc decodeSOF0(state: var DecoderState) =
if quantizationTableId > 3: if quantizationTableId > 3:
failInvalid("invalid quantization table id") failInvalid("invalid quantization table id")
if vertical notin {1, 2, 4} or horizontal notin {1, 2, 4}: if vertical notin {1'u8, 2, 4} or horizontal notin {1'u8, 2, 4}:
failInvalid("invalid component scaling factor") failInvalid("invalid component scaling factor")
component.xScale = vertical.int component.xScale = vertical.int
@ -443,13 +444,13 @@ proc reset(state: var DecoderState) =
proc decodeSOS(state: var DecoderState) = proc decodeSOS(state: var DecoderState) =
## Decode Start of Scan - header before the block data. ## Decode Start of Scan - header before the block data.
var len = state.readUint16be() - 2 var len = state.readUint16be() - 2
let scanComponentsU8 = state.readUint8()
state.scanComponents = state.readUint8().int state.scanComponents = scanComponentsU8.int
if state.scanComponents > state.components.len: if state.scanComponents > state.components.len:
failInvalid("extra components") failInvalid("extra components")
if state.scanComponents notin {1, 3}: if scanComponentsU8 notin {1'u8, 3}:
failInvalid("unsupported scan component count") failInvalid("unsupported scan component count")
state.componentOrder.setLen(0) state.componentOrder.setLen(0)
@ -878,7 +879,7 @@ proc checkRestart(state: var DecoderState) =
if state.pos + 1 > state.len: if state.pos + 1 > state.len:
failInvalid() failInvalid()
if state.buffer[state.pos] != 0xFF or if state.buffer[state.pos] != 0xFF or
state.buffer[state.pos + 1] notin {0xD0 .. 0xD7}: state.buffer[state.pos + 1] notin 0xD0'u8 .. 0xD7'u8:
failInvalid("did not get expected restart marker") failInvalid("did not get expected restart marker")
state.pos += 2 state.pos += 2
state.reset() state.reset()

View file

@ -60,7 +60,7 @@ proc decodeQoi*(data: string): Qoi {.raises: [PixieError].} =
channels = data.readUint8(12) channels = data.readUint8(12)
colorspace = data.readUint8(13) colorspace = data.readUint8(13)
if channels notin {3, 4} or colorspace notin {0, 1}: if channels notin {3'u8, 4} or colorspace notin {0'u8, 1}:
raise newException(PixieError, "Invalid QOI header") raise newException(PixieError, "Invalid QOI header")
if width.int * height.int > uint32.high.int64: if width.int * height.int > uint32.high.int64: