Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Clone ImageTestSuite
shell: bash
run: git clone --depth 1 https://github.com/treeform/imagetestsuite ../imagetestsuite
- uses: treeform/setup-nim-action@v6
- name: Install dependencies
shell: bash
Expand All @@ -22,3 +25,4 @@ jobs:
nimby install -g pixie/pixie.nimble
- run: nim r tests/tests.nim
- run: nim cpp -r tests/tests.nim
- run: nim r tests/imagetestsuite.nim
16 changes: 7 additions & 9 deletions src/pixie/fileformats/gif.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ proc decodeGif*(data: string): Gif {.raises: [PixieError].} =
hasGlobalColorTable = (globalFlags and 0b10000000) != 0
globalColorTableSize = 2 ^ ((globalFlags and 0b00000111) + 1)
bgColorIndex = data.readUint8(11).int
pixelAspectRatio = data.readUint8(12)

if bgColorIndex >= globalColorTableSize:
if hasGlobalColorTable and bgColorIndex >= globalColorTableSize:
failInvalid()

if pixelAspectRatio != 0:
raise newException(PixieError, "Unsupported GIF, pixel aspect ratio")

var pos = 13

if pos + globalColorTableSize * 3 > data.len:
if hasGlobalColorTable and pos + globalColorTableSize * 3 > data.len:
failInvalid()

var
Expand Down Expand Up @@ -79,6 +75,8 @@ proc decodeGif*(data: string): Gif {.raises: [PixieError].} =
break

pos += subBlockSize
if pos > data.len:
failInvalid()

var controlExtension: ControlExtension
while true:
Expand All @@ -98,7 +96,7 @@ proc decodeGif*(data: string): Gif {.raises: [PixieError].} =
imageTopPos = data.readUint16(pos + 2).int
imageWidth = data.readUint16(pos + 4).int
imageHeight = data.readUint16(pos + 6).int
imageFlags = data.readUint16(pos + 8)
imageFlags = data.readUint8(pos + 8)
hasLocalColorTable = (imageFlags and 0b10000000) != 0
interlaced = (imageFlags and 0b01000000) != 0
localColorTableSize = 2 ^ ((imageFlags and 0b00000111) + 1)
Expand All @@ -108,7 +106,7 @@ proc decodeGif*(data: string): Gif {.raises: [PixieError].} =
if imageWidth > screenWidth or imageHeight > screenHeight:
raise newException(PixieError, "Invalid GIF frame dimensions")

if pos + localColorTableSize * 3 > data.len:
if hasLocalColorTable and pos + localColorTableSize * 3 > data.len:
failInvalid()

var localColorTable: seq[ColorRGBX]
Expand All @@ -129,7 +127,7 @@ proc decodeGif*(data: string): Gif {.raises: [PixieError].} =
let minCodeSize = data.readUint8(pos).int
inc pos

if minCodeSize > 11:
if minCodeSize < 2 or minCodeSize > 8:
failInvalid()

# The image data is contained in a sequence of sub-blocks
Expand Down
Loading