Skip to content

Commit 5f7c12e

Browse files
authored
libnsgif: Update to latest upstream. (#2706)
1 parent c0de1b6 commit 5f7c12e

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

libvips/foreign/libnsgif/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ but within the libvips build system.
88
Run `./update.sh` to update this copy of libnsgif from the upstream repo. It
99
will also patch libnsgif.c to prevent it modifying the input.
1010

11-
Last updated 7 Oct 2021.
11+
Last updated 3 Mar 2022.
1212

1313
# To do
1414

libvips/foreign/libnsgif/gif.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,15 @@ static void nsgif__restore_bg(
625625
uint32_t offset_x = frame->info.rect.x0;
626626
uint32_t offset_y = frame->info.rect.y0;
627627

628-
width -= gif__clip(offset_x, width, gif->info.width);
629-
height -= gif__clip(offset_y, height, gif->info.height);
630-
631-
if (frame->info.display == false || width == 0) {
628+
if (frame->info.display == false ||
629+
frame->info.rect.x0 >= gif->info.width ||
630+
frame->info.rect.y0 >= gif->info.height) {
632631
return;
633632
}
634633

634+
width -= gif__clip(offset_x, width, gif->info.width);
635+
height -= gif__clip(offset_y, height, gif->info.height);
636+
635637
if (frame->info.transparency) {
636638
for (uint32_t y = 0; y < height; y++) {
637639
uint32_t *scanline = bitmap + offset_x +
@@ -1703,7 +1705,7 @@ nsgif_error nsgif_frame_decode(
17031705
uint32_t start_frame;
17041706
nsgif_error ret = NSGIF_OK;
17051707

1706-
if (frame > gif->info.frame_count) {
1708+
if (frame >= gif->info.frame_count) {
17071709
return NSGIF_ERR_BAD_FRAME;
17081710
}
17091711

@@ -1742,7 +1744,7 @@ const nsgif_frame_info_t *nsgif_get_frame_info(
17421744
const nsgif_t *gif,
17431745
uint32_t frame)
17441746
{
1745-
if (frame > gif->info.frame_count) {
1747+
if (frame >= gif->info.frame_count) {
17461748
return NULL;
17471749
}
17481750

@@ -1759,8 +1761,7 @@ const char *nsgif_strerror(nsgif_error err)
17591761
[NSGIF_ERR_BAD_FRAME] = "Requested frame does not exist",
17601762
[NSGIF_ERR_DATA_FRAME] = "Invalid frame data",
17611763
[NSGIF_ERR_FRAME_COUNT] = "Excessive number of frames",
1762-
[NSGIF_ERR_END_OF_DATA] = "Insufficient data for first frame",
1763-
[NSGIF_ERR_END_OF_FRAME] = "End of data during frame",
1764+
[NSGIF_ERR_END_OF_DATA] = "Unexpected end of GIF source data",
17641765
[NSGIF_ERR_FRAME_DISPLAY] = "Frame can't be displayed",
17651766
[NSGIF_ERR_ANIMATION_END] = "Animation complete",
17661767
};

libvips/foreign/libnsgif/nsgif.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,10 @@ typedef enum {
8282
NSGIF_ERR_FRAME_COUNT,
8383

8484
/**
85-
* GIF source data ended without one complete frame available.
85+
* Unexpected end of GIF source data.
8686
*/
8787
NSGIF_ERR_END_OF_DATA,
8888

89-
/**
90-
* GIF source data ended with incomplete frame.
91-
*/
92-
NSGIF_ERR_END_OF_FRAME,
93-
9489
/**
9590
* The current frame cannot be displayed.
9691
*/
@@ -215,6 +210,9 @@ void nsgif_destroy(nsgif_t *gif);
215210
*
216211
* If an error occurs, all previously scanned frames are retained.
217212
*
213+
* Note that an error returned from this function is purely informational.
214+
* So long as at least one frame is available, you can display frames.
215+
*
218216
* \param[in] gif The \ref nsgif_t object.
219217
* \param[in] size Number of bytes in data.
220218
* \param[in] data Raw source GIF data.

libvips/foreign/libnsgif/test/nsgif.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,21 @@ static void decode(FILE* ppm, const char *name, nsgif_t *gif)
207207
}
208208
frame_prev = frame_new;
209209

210-
err = nsgif_frame_decode(gif, frame_new, &bitmap);
211-
if (err != NSGIF_OK) {
212-
warning("nsgif_decode_frame", err);
213-
return;
214-
}
215-
216210
if (nsgif_options.info == true) {
217211
const nsgif_frame_info_t *f_info;
218212

219213
f_info = nsgif_get_frame_info(gif, frame_new);
220-
assert(f_info != NULL);
221-
print_gif_frame_info(f_info);
214+
if (f_info != NULL) {
215+
print_gif_frame_info(f_info);
216+
}
222217
}
223218

224-
if (ppm != NULL) {
219+
err = nsgif_frame_decode(gif, frame_new, &bitmap);
220+
if (err != NSGIF_OK) {
221+
warning("nsgif_decode_frame", err);
222+
/* Continue decoding the rest of the frames. */
223+
224+
} else if (ppm != NULL) {
225225
fprintf(ppm, "# frame %u:\n", frame_new);
226226
image = (const uint8_t *) bitmap;
227227
for (uint32_t y = 0; y != info->height; y++) {
@@ -284,10 +284,9 @@ int main(int argc, char *argv[])
284284
/* Scan the raw data */
285285
err = nsgif_data_scan(gif, size, data);
286286
if (err != NSGIF_OK) {
287+
/* Not fatal; some GIFs are nasty. Can still try to decode
288+
* any frames that were decoded successfully. */
287289
warning("nsgif_data_scan", err);
288-
nsgif_destroy(gif);
289-
free(data);
290-
return EXIT_FAILURE;
291290
}
292291

293292
if (nsgif_options.loops == 0) {

0 commit comments

Comments
 (0)