Gitweb links:
...log
http://git.netsurf-browser.org/libnsgif.git/shortlog/eebf25066c18fbf04b83...
...commit
http://git.netsurf-browser.org/libnsgif.git/commit/eebf25066c18fbf04b8324...
...tree
http://git.netsurf-browser.org/libnsgif.git/tree/eebf25066c18fbf04b832403...
The branch, tlsa/rewrite has been updated
via eebf25066c18fbf04b8324030f1989870bb0f38e (commit)
via 24c503f95e1f9ef726e546e616649120b666d15d (commit)
from 5e0642811e2edce8d8845fdf0bcb8f9eefc71f80 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=eebf25066c18fbf04b...
commit eebf25066c18fbf04b8324030f1989870bb0f38e
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
GIF: Constify raw source data.
diff --git a/include/libnsgif.h b/include/libnsgif.h
index ae6691c..d0d16ac 100644
--- a/include/libnsgif.h
+++ b/include/libnsgif.h
@@ -15,8 +15,8 @@
#ifndef _LIBNSGIF_H_
#define _LIBNSGIF_H_
+#include <stdint.h>
#include <stdbool.h>
-#include <inttypes.h>
/* Error return values */
typedef enum {
@@ -100,7 +100,7 @@ typedef struct gif_animation {
/** callbacks for bitmap functions */
gif_bitmap_callback_vt bitmap_callbacks;
/** pointer to GIF data */
- unsigned char *gif_data;
+ const uint8_t *gif_data;
/** width of GIF (may increase during decoding) */
unsigned int width;
/** heigth of GIF (may increase during decoding) */
diff --git a/src/libnsgif.c b/src/libnsgif.c
index c2a8c73..21f319e 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -527,7 +527,7 @@ static gif_result gif__update_bitmap(
*/
static gif_result gif__parse_extension_graphic_control(
struct gif_frame *frame,
- uint8_t *data,
+ const uint8_t *data,
size_t len)
{
/* 6-byte Graphic Control Extension is:
@@ -583,7 +583,7 @@ static gif_result gif__parse_extension_graphic_control(
*/
static gif_result gif__parse_extension_application(
struct gif_animation *gif,
- uint8_t *data,
+ const uint8_t *data,
size_t len)
{
/* 14-byte+ Application Extension is:
@@ -619,11 +619,11 @@ static gif_result gif__parse_extension_application(
static gif_result gif__parse_frame_extensions(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
- uint8_t *gif_data = *pos;
- uint8_t *gif_end = gif->gif_data + gif->buffer_size;
+ const uint8_t *gif_data = *pos;
+ const uint8_t *gif_end = gif->gif_data + gif->buffer_size;
int gif_bytes = gif_end - gif_data;
/* Initialise the extensions */
@@ -727,7 +727,7 @@ static gif_result gif__parse_frame_extensions(
static gif_result gif__parse_image_descriptor(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
const uint8_t *data = *pos;
@@ -783,7 +783,7 @@ static gif_result gif__parse_image_descriptor(
static gif_result gif__parse_colour_table(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
unsigned colour_table_size;
@@ -840,10 +840,10 @@ static gif_result gif__parse_colour_table(
static gif_result gif__parse_image_data(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
- uint8_t *data = *pos;
+ const uint8_t *data = *pos;
size_t len = gif->gif_data + gif->buffer_size - data;
uint32_t frame_idx = frame - gif->frames;
uint8_t minimum_code_size;
@@ -970,9 +970,9 @@ static gif_result gif__process_frame(
uint32_t frame_idx,
bool decode)
{
- uint8_t *pos;
- uint8_t *end;
gif_result ret;
+ const uint8_t *pos;
+ const uint8_t *end;
struct gif_frame *frame;
frame = gif__get_frame(gif, frame_idx);
@@ -980,7 +980,7 @@ static gif_result gif__process_frame(
return GIF_INSUFFICIENT_MEMORY;
}
- end = (uint8_t *)(gif->gif_data + gif->buffer_size);
+ end = gif->gif_data + gif->buffer_size;
if (decode) {
pos = gif->gif_data + frame->frame_pointer;
@@ -1057,7 +1057,7 @@ void gif_create(gif_animation *gif, gif_bitmap_callback_vt
*bitmap_callbacks)
/* exported function documented in libnsgif.h */
gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data)
{
- uint8_t *gif_data;
+ const uint8_t *gif_data;
uint32_t index;
gif_result ret;
commitdiff
http://git.netsurf-browser.org/libnsgif.git/commit/?id=24c503f95e1f9ef726...
commit 24c503f95e1f9ef726e546e616649120b666d15d
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
GIF: Don't write into the GIF source data to handle errors.
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 2a1fdfe..c2a8c73 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -887,25 +887,13 @@ static gif_result gif__parse_image_data(
if (len < 1) return GIF_INSUFFICIENT_FRAME_DATA;
block_size = data[0] + 1;
/* Check if the frame data runs off the end of the file */
- if ((int)(len - block_size) < 0) {
- /* Try to recover by signaling the end of the gif.
- * Once we get garbage data, there is no logical way to
- * determine where the next frame is. It's probably
- * better to partially load the gif than not at all.
- */
- if (len >= 2) {
- data[0] = 0;
- data[1] = GIF_TRAILER;
- len = 1;
- data++;
- break;
- } else {
- return GIF_INSUFFICIENT_FRAME_DATA;
- }
- } else {
- len -= block_size;
- data += block_size;
+ if (block_size > len) {
+ block_size = len;
+ return GIF_OK;
}
+
+ len -= block_size;
+ data += block_size;
}
gif->frame_count = frame_idx + 1;
-----------------------------------------------------------------------
Summary of changes:
include/libnsgif.h | 4 ++--
src/libnsgif.c | 50 +++++++++++++++++++-------------------------------
2 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/include/libnsgif.h b/include/libnsgif.h
index ae6691c..d0d16ac 100644
--- a/include/libnsgif.h
+++ b/include/libnsgif.h
@@ -15,8 +15,8 @@
#ifndef _LIBNSGIF_H_
#define _LIBNSGIF_H_
+#include <stdint.h>
#include <stdbool.h>
-#include <inttypes.h>
/* Error return values */
typedef enum {
@@ -100,7 +100,7 @@ typedef struct gif_animation {
/** callbacks for bitmap functions */
gif_bitmap_callback_vt bitmap_callbacks;
/** pointer to GIF data */
- unsigned char *gif_data;
+ const uint8_t *gif_data;
/** width of GIF (may increase during decoding) */
unsigned int width;
/** heigth of GIF (may increase during decoding) */
diff --git a/src/libnsgif.c b/src/libnsgif.c
index 2a1fdfe..21f319e 100644
--- a/src/libnsgif.c
+++ b/src/libnsgif.c
@@ -527,7 +527,7 @@ static gif_result gif__update_bitmap(
*/
static gif_result gif__parse_extension_graphic_control(
struct gif_frame *frame,
- uint8_t *data,
+ const uint8_t *data,
size_t len)
{
/* 6-byte Graphic Control Extension is:
@@ -583,7 +583,7 @@ static gif_result gif__parse_extension_graphic_control(
*/
static gif_result gif__parse_extension_application(
struct gif_animation *gif,
- uint8_t *data,
+ const uint8_t *data,
size_t len)
{
/* 14-byte+ Application Extension is:
@@ -619,11 +619,11 @@ static gif_result gif__parse_extension_application(
static gif_result gif__parse_frame_extensions(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
- uint8_t *gif_data = *pos;
- uint8_t *gif_end = gif->gif_data + gif->buffer_size;
+ const uint8_t *gif_data = *pos;
+ const uint8_t *gif_end = gif->gif_data + gif->buffer_size;
int gif_bytes = gif_end - gif_data;
/* Initialise the extensions */
@@ -727,7 +727,7 @@ static gif_result gif__parse_frame_extensions(
static gif_result gif__parse_image_descriptor(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
const uint8_t *data = *pos;
@@ -783,7 +783,7 @@ static gif_result gif__parse_image_descriptor(
static gif_result gif__parse_colour_table(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
unsigned colour_table_size;
@@ -840,10 +840,10 @@ static gif_result gif__parse_colour_table(
static gif_result gif__parse_image_data(
struct gif_animation *gif,
struct gif_frame *frame,
- uint8_t **pos,
+ const uint8_t **pos,
bool decode)
{
- uint8_t *data = *pos;
+ const uint8_t *data = *pos;
size_t len = gif->gif_data + gif->buffer_size - data;
uint32_t frame_idx = frame - gif->frames;
uint8_t minimum_code_size;
@@ -887,25 +887,13 @@ static gif_result gif__parse_image_data(
if (len < 1) return GIF_INSUFFICIENT_FRAME_DATA;
block_size = data[0] + 1;
/* Check if the frame data runs off the end of the file */
- if ((int)(len - block_size) < 0) {
- /* Try to recover by signaling the end of the gif.
- * Once we get garbage data, there is no logical way to
- * determine where the next frame is. It's probably
- * better to partially load the gif than not at all.
- */
- if (len >= 2) {
- data[0] = 0;
- data[1] = GIF_TRAILER;
- len = 1;
- data++;
- break;
- } else {
- return GIF_INSUFFICIENT_FRAME_DATA;
- }
- } else {
- len -= block_size;
- data += block_size;
+ if (block_size > len) {
+ block_size = len;
+ return GIF_OK;
}
+
+ len -= block_size;
+ data += block_size;
}
gif->frame_count = frame_idx + 1;
@@ -982,9 +970,9 @@ static gif_result gif__process_frame(
uint32_t frame_idx,
bool decode)
{
- uint8_t *pos;
- uint8_t *end;
gif_result ret;
+ const uint8_t *pos;
+ const uint8_t *end;
struct gif_frame *frame;
frame = gif__get_frame(gif, frame_idx);
@@ -992,7 +980,7 @@ static gif_result gif__process_frame(
return GIF_INSUFFICIENT_MEMORY;
}
- end = (uint8_t *)(gif->gif_data + gif->buffer_size);
+ end = gif->gif_data + gif->buffer_size;
if (decode) {
pos = gif->gif_data + frame->frame_pointer;
@@ -1069,7 +1057,7 @@ void gif_create(gif_animation *gif, gif_bitmap_callback_vt
*bitmap_callbacks)
/* exported function documented in libnsgif.h */
gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data)
{
- uint8_t *gif_data;
+ const uint8_t *gif_data;
uint32_t index;
gif_result ret;
--
NetSurf GIF Decoder