Skip to content

Commit 620f6f2

Browse files
committed
backport #70 to v0.4
1 parent dc470eb commit 620f6f2

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,34 @@ on:
44
- pull_request
55
jobs:
66
build:
7+
name: ${{ matrix.name }}
78
runs-on: ${{ matrix.os }}
89
strategy:
910
matrix:
10-
os:
11-
- ubuntu-22.04
12-
- macos-12
13-
- windows-2022
11+
include:
12+
- name: "Linux x64 (Ubuntu 22.04)"
13+
os: ubuntu-22.04
14+
config: {}
15+
- name: "Linux 32-bit (Ubuntu 22.04)"
16+
os: ubuntu-22.04
17+
config: { cflags: "-m32"}
18+
- name: "macOS 12"
19+
os: macos-12
20+
config: {}
21+
- name: "Windows 2022"
22+
os: windows-2022
23+
config: {}
24+
env:
25+
CFLAGS: ${{ matrix.config.cflags }}
1426
steps:
1527
- uses: actions/checkout@v4
1628
- uses: actions/setup-python@v5
1729
- name: Dependencies (ubuntu)
1830
if: contains(matrix.os, 'ubuntu')
1931
run: sudo apt update && sudo apt install -y gifsicle valgrind meson
32+
- name: Dependencies (ubuntu 32-bit)
33+
if: contains(matrix.name, '32-bit')
34+
run: sudo apt update && sudo apt install -y gcc-multilib
2035
- name: Dependencies (macos)
2136
if: contains(matrix.os, 'macos')
2237
run: brew install gifsicle meson
@@ -33,9 +48,9 @@ jobs:
3348
run: for f in build/*.gif; do gifsicle --no-ignore-errors --info $f || exit 1; done
3449
shell: bash
3550
- name: Valgrind
36-
if: contains(matrix.os, 'ubuntu')
51+
if: contains(matrix.name, 'Linux x64')
3752
run: meson test -C build --list | grep -v zip | grep -v checksums | sed 's/^/"/;s/$/"/' | xargs meson test -C build/ --wrap "valgrind --memcheck:leak-check=full --memcheck:show-leak-kinds=definite --memcheck:error-exitcode=1"
3853
shell: bash
3954
- name: Valgrind output
40-
if: contains(matrix.os, 'ubuntu')
55+
if: contains(matrix.name, 'Linux x64')
4156
run: cat build/meson-logs/testlog-valgrind.txt

src/cgif_raw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ static int LZW_GenerateStream(LZWResult* pResult, const uint32_t numPixel, const
323323
// pack the generated LZW data into blocks of 255 bytes
324324
uint8_t *byteList; // lzw-data packed in byte-list
325325
uint8_t *byteListBlock; // lzw-data packed in byte-list with 255-block structure
326-
uint64_t MaxByteListLen = MAX_CODE_LEN*lzwPos/8ul +2ul +1ul; // conservative upper bound
327-
uint64_t MaxByteListBlockLen = MAX_CODE_LEN*lzwPos*(BLOCK_SIZE+1ul)/8ul/BLOCK_SIZE +2ul +1ul +1ul; // conservative upper bound
326+
uint64_t MaxByteListLen = MAX_CODE_LEN * lzwPos / 8ull + 2ull + 1ull; // conservative upper bound
327+
uint64_t MaxByteListBlockLen = MAX_CODE_LEN * lzwPos * (BLOCK_SIZE + 1ull) / 8ull / BLOCK_SIZE + 2ull + 1ull +1ull; // conservative upper bound
328328
byteList = malloc(MaxByteListLen); // TBD check return value of malloc
329329
byteListBlock = malloc(MaxByteListBlockLen); // TBD check return value of malloc
330330
bytePos = create_byte_list(byteList,lzwPos, pContext->pLZWData, initDictLen, initCodeLen);

tests/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ tests = [
3030
{ 'name' : 'min_size', 'seed_should_fail' : false},
3131
{ 'name' : 'more_than_256_colors', 'seed_should_fail' : false},
3232
{ 'name' : 'noise256', 'seed_should_fail' : false},
33+
{ 'name' : 'noise256_large', 'seed_should_fail' : false},
3334
{ 'name' : 'noise6', 'seed_should_fail' : false},
3435
{ 'name' : 'noise6_interlaced', 'seed_should_fail' : false},
3536
{ 'name' : 'noloop', 'seed_should_fail' : false},

tests/noise256_large.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <stdlib.h>
2+
#include <stdint.h>
3+
#include <string.h>
4+
#include <stdio.h>
5+
6+
#include "cgif.h"
7+
8+
#define WIDTH 3000
9+
#define HEIGHT 3000
10+
11+
static uint64_t seed;
12+
13+
// unsigned integer overflow expected
14+
__attribute__((no_sanitize("integer")))
15+
int psdrand(void) {
16+
// simple pseudo random function from musl libc
17+
seed = 6364136223846793005ULL * seed + 1;
18+
return seed >> 33;
19+
}
20+
21+
int main(void) {
22+
CGIF* pGIF;
23+
CGIF_Config gConfig;
24+
CGIF_FrameConfig fConfig;
25+
uint8_t* pImageData;
26+
cgif_result r;
27+
uint8_t aPalette[256 * 3];
28+
29+
seed = 22;
30+
for(int i = 0; i < 256; ++i) {
31+
aPalette[i * 3] = psdrand() % 256;
32+
aPalette[i * 3 + 1] = psdrand() % 256;
33+
aPalette[i * 3 + 2] = psdrand() % 256;
34+
}
35+
memset(&gConfig, 0, sizeof(CGIF_Config));
36+
memset(&fConfig, 0, sizeof(CGIF_FrameConfig));
37+
gConfig.width = WIDTH;
38+
gConfig.height = HEIGHT;
39+
gConfig.pGlobalPalette = aPalette;
40+
gConfig.numGlobalPaletteEntries = 256;
41+
gConfig.path = "noise256_large.gif";
42+
//
43+
// create new GIF
44+
pGIF = cgif_newgif(&gConfig);
45+
if(pGIF == NULL) {
46+
fputs("failed to create new GIF via cgif_newgif()\n", stderr);
47+
return 1;
48+
}
49+
//
50+
// add frames to GIF
51+
pImageData = malloc(WIDTH * HEIGHT);
52+
for(int i = 0; i < WIDTH * HEIGHT; ++i) pImageData[i] = psdrand() % 256;
53+
fConfig.pImageData = pImageData;
54+
r = cgif_addframe(pGIF, &fConfig);
55+
free(pImageData);
56+
//
57+
// write GIF to file
58+
r = cgif_close(pGIF); // free allocated space at the end of the session
59+
60+
// check for errors
61+
if(r != CGIF_OK) {
62+
fprintf(stderr, "failed to create GIF. error code: %d\n", r);
63+
return 2;
64+
}
65+
return 0;
66+
}

tests/tests.sha256

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ eeb9acd181da401748c9f39c59dbb5ecd71fd6f8f1685002f767de2ec0329bf4 min_color_tabl
2121
b263ce6bde416426b6676c320846f73870d40b2125bfc9630087c3c54df21ac8 min_size.gif
2222
5244e4ca77ea3923d27e790b9dddb6032a686e0272ba3d78ff5fa4af0523647b more_than_256_colors.gif
2323
11c8de343ccd528e319afbe3ec0d0c657c1e6292faf6cb318713bcaf2979ab0d noise256.gif
24+
75a2a7b04a21b785977fb2506e6468478418703835876755e78453223820b924 noise256_large.gif
2425
ff1da19b0448af07d8561f0ee62b184f99ac7dcb75f1a2215474190ec6648901 noise6.gif
2526
14cd8b2486e725d4136e1af656aa2398a882694fd1774ebfb23c57dae5ae00da noise6_interlaced.gif
2627
98ec5ef9223f2c51bc2f4f94da4468f3b1e3c537a64d8050649787aaf433d13d noloop.gif

0 commit comments

Comments
 (0)