Skip to content

Commit 533cb97

Browse files
committed
An integer overflow will lead to heap memory corruption with large (~2GB) inputs. Origin: ppisar@23cea2d Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040036 Bug: lloyd#239
1 parent d070426 commit 533cb97

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/yajl_buf.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ void yajl_buf_ensure_available(yajl_buf buf, size_t want)
4545

4646
need = buf->len;
4747

48-
while (want >= (need - buf->used)) need <<= 1;
48+
if (((buf->used > want) ? buf->used : want) > (size_t)(buf->used + want)) {
49+
/* We cannot allocate more memory than SIZE_MAX. */
50+
abort();
51+
}
52+
while (want >= (need - buf->used)) {
53+
if (need >= (size_t)((size_t)(-1)<<1)>>1) {
54+
/* need would overflow. */
55+
abort();
56+
}
57+
need <<= 1;
58+
}
4959

5060
if (need != buf->len) {
5161
buf->data = (unsigned char *) YA_REALLOC(buf->alloc, buf->data, need);

0 commit comments

Comments
 (0)