Skip to content

Commit

Permalink
Merge pull request #6 from jangko/fix_invalid_datasize
Browse files Browse the repository at this point in the history
fix invalid datasize
  • Loading branch information
jangko authored Jul 17, 2020
2 parents 6a29e20 + 1d52237 commit d419da8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
16 changes: 8 additions & 8 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '{build}'

cache:
- x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z -> .appveyor.yml
- i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z -> .appveyor.yml
- Nim -> .appveyor.yml
- x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z -> .appveyor.yml
- i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z -> .appveyor.yml
- Nim -> .appveyor.yml

matrix:
# We always want 32 and 64-bit compilation
Expand All @@ -17,13 +17,13 @@ install:
- setlocal EnableExtensions EnableDelayedExpansion

- IF "%PLATFORM%" == "x86" (
SET "MINGW_ARCHIVE=i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" &
SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win32/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/dwarf/i686-4.9.2-release-win32-dwarf-rt_v4-rev4.7z" &
SET "MINGW_ARCHIVE=i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z" &
SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win32/Personal%%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z" &
SET "MINGW_DIR=mingw32"
) ELSE (
IF "%PLATFORM%" == "x64" (
SET "MINGW_ARCHIVE=x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" &
SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win64/Personal%%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z" &
SET "MINGW_ARCHIVE=x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z" &
SET "MINGW_URL=https://sourceforge.net/projects/mingw-w64/files/Toolchains%%20targetting%%20Win64/Personal%%20Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z" &
SET "MINGW_DIR=mingw64"
) else (
echo "Unknown platform"
Expand All @@ -42,7 +42,7 @@ install:
- SET "NEED_REBUILD="

- IF NOT EXIST "Nim\\.git\\" (
git clone https://github.com/nim-lang/Nim.git
git clone --depth 1 https://github.com/nim-lang/Nim.git
) ELSE (
( cd Nim ) &
( git pull ) &
Expand Down
2 changes: 1 addition & 1 deletion nimBMP.nim
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ proc decodeBMP*(s: Stream): BMP =

if info.imageSize == 0:
info.imageSize = DWORD(dataSize)
if dataSize + int64(header.offset) != int64(header.fileSize):
if dataSize + int64(header.offset) > int64(header.fileSize):
raise BMPError("invalid dataSize")

if dataSize > int64(info.imageSize):
Expand Down
8 changes: 7 additions & 1 deletion nimBMP.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packageName = "nimBMP"
version = "0.1.7"
version = "0.1.8"
author = "Andri Lim"
description = "BMP encoder and decoder"
license = "MIT"
Expand All @@ -11,6 +11,12 @@ task tests, "Run tests":
withDir("tests"):
exec "nim c -r testCodec.nim"
exec "nim c -r testSuite.nim"
exec "nim c -r test_misc.nim"

exec "nim c -r -d:release testCodec.nim"
exec "nim c -r -d:release testSuite.nim"
exec "nim c -r -d:release test_misc.nim"

exec "nim c -r -d:release --gc:arc testCodec.nim"
exec "nim c -r -d:release --gc:arc testSuite.nim"
exec "nim c -r -d:release --gc:arc test_misc.nim"
Binary file added tests/misc/1bit.bmp
Binary file not shown.
Binary file added tests/misc/4bit.bmp
Binary file not shown.
Binary file added tests/misc/8bit.bmp
Binary file not shown.
19 changes: 19 additions & 0 deletions tests/test_misc.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ../nimBMP, os, unittest

const testFolder = "misc"

suite "misc test":
test "1bit":
var bmp = loadBMP24(testFolder / "1bit.bmp")
check bmp.width == 96
check bmp.height == 16

test "4bit":
var bmp = loadBMP24(testFolder / "4bit.bmp")
check bmp.width == 134
check bmp.height == 38

test "8bit":
var bmp = loadBMP24(testFolder / "8bit.bmp")
check bmp.width == 216
check bmp.height == 143

0 comments on commit d419da8

Please sign in to comment.