validate
This commit is contained in:
parent
30fc7c73c9
commit
8036516c7d
1 changed files with 8 additions and 1 deletions
|
@ -212,7 +212,7 @@ proc decodeDHT(state: var DecoderState) =
|
||||||
|
|
||||||
proc decodeSOF0(state: var DecoderState) =
|
proc decodeSOF0(state: var DecoderState) =
|
||||||
## Decode start of Frame
|
## Decode start of Frame
|
||||||
var len = state.readUint16be() - 2
|
var len = state.readUint16be().int - 2
|
||||||
|
|
||||||
let precision = state.readUint8()
|
let precision = state.readUint8()
|
||||||
if precision != 8:
|
if precision != 8:
|
||||||
|
@ -230,6 +230,8 @@ proc decodeSOF0(state: var DecoderState) =
|
||||||
if numComponents notin {1, 3}:
|
if numComponents notin {1, 3}:
|
||||||
failInvalid("unsupported component count, must be 1 or 3")
|
failInvalid("unsupported component count, must be 1 or 3")
|
||||||
|
|
||||||
|
len -= 6
|
||||||
|
|
||||||
for i in 0 ..< numComponents:
|
for i in 0 ..< numComponents:
|
||||||
var component = Component()
|
var component = Component()
|
||||||
component.id = state.readUint8()
|
component.id = state.readUint8()
|
||||||
|
@ -250,6 +252,8 @@ proc decodeSOF0(state: var DecoderState) =
|
||||||
component.quantizationTableId = quantizationTableId
|
component.quantizationTableId = quantizationTableId
|
||||||
state.components.add(component)
|
state.components.add(component)
|
||||||
|
|
||||||
|
len -= 3 * numComponents
|
||||||
|
|
||||||
for component in state.components.mitems:
|
for component in state.components.mitems:
|
||||||
state.maxXScale = max(state.maxXScale, component.xScale)
|
state.maxXScale = max(state.maxXScale, component.xScale)
|
||||||
state.maxYScale = max(state.maxYScale, component.yScale)
|
state.maxYScale = max(state.maxYScale, component.yScale)
|
||||||
|
@ -292,6 +296,9 @@ proc decodeSOF0(state: var DecoderState) =
|
||||||
component.widthStride * component.heightStride
|
component.widthStride * component.heightStride
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if len != 0:
|
||||||
|
failInvalid()
|
||||||
|
|
||||||
proc decodeSOF1(state: var DecoderState) =
|
proc decodeSOF1(state: var DecoderState) =
|
||||||
failInvalid("unsupported extended sequential DCT format")
|
failInvalid("unsupported extended sequential DCT format")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue