Skip to content

Commit 9f0f0c8

Browse files
committed
Limit maximum length of comment
1 parent 3d90c88 commit 9f0f0c8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

android-gif-drawable/src/main/c/decoding.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "gif.h"
2+
#define COMMENT_LENGTH_MAX 2048
23

34
static bool updateGCB(GifInfo *info, uint_fast32_t *lastAllocatedGCBIndex) {
45
if (*lastAllocatedGCBIndex < info->gifFilePtr->ImageCount) {
@@ -177,12 +178,16 @@ static int readExtensions(int ExtFunction, GifByteType *ExtData, GifInfo *info)
177178
}
178179

179180
static int getComment(GifByteType *Bytes, GifInfo *info) {
180-
unsigned int len = (unsigned int) Bytes[0];
181+
unsigned int length = (unsigned int) Bytes[0];
181182
size_t offset = info->comment != NULL ? strlen(info->comment) : 0;
182-
char *ret = reallocarray(info->comment, len + offset + 1, sizeof(char));
183+
unsigned int newLength = length + offset + 1;
184+
if (newLength > COMMENT_LENGTH_MAX) {
185+
return GIF_OK;
186+
}
187+
char *ret = reallocarray(info->comment, newLength, sizeof(char));
183188
if (ret != NULL) {
184-
memcpy(ret + offset, &Bytes[1], len);
185-
ret[len + offset] = 0;
189+
memcpy(ret + offset, &Bytes[1], length);
190+
ret[length + offset] = 0;
186191
info->comment = ret;
187192
return GIF_OK;
188193
}

0 commit comments

Comments
 (0)