| 1 |
/* |
| 2 |
* Reproducer for GHSA-wpx3-h5g8-qr3w. |
| 3 |
* |
| 4 |
* sixel_decode() has the same palette allocation check as |
| 5 |
* sixel_decode_raw(). The raster attributes keep the deprecated wrapper's |
| 6 |
* initial 2048x2048 buffer from being resized before the palette allocation, |
| 7 |
* making the third malloc call the palette allocation. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "config.h" |
| 11 |
|
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
#include <sixel.h> |
| 16 |
|
| 17 |
static int malloc_count; |
| 18 |
|
| 19 |
static void * |
| 20 |
fail_palette_malloc(size_t size) |
| 21 |
{ |
| 22 |
++malloc_count; |
| 23 |
if (malloc_count == 3) { |
| 24 |
return NULL; |
| 25 |
} |
| 26 |
|
| 27 |
return malloc(size); |
| 28 |
} |
| 29 |
|
| 30 |
int |
| 31 |
main(void) |
| 32 |
{ |
| 33 |
static unsigned char sixel[] = "\033Pq\"1;1;2048;2048q\033\\"; |
| 34 |
unsigned char *pixels; |
| 35 |
unsigned char *palette; |
| 36 |
SIXELSTATUS status; |
| 37 |
int width; |
| 38 |
int height; |
| 39 |
int ncolors; |
| 40 |
|
| 41 |
pixels = NULL; |
| 42 |
palette = NULL; |
| 43 |
width = 0; |
| 44 |
height = 0; |
| 45 |
ncolors = 0; |
| 46 |
|
| 47 |
#if defined(__GNUC__) || defined(__clang__) |
| 48 |
# pragma GCC diagnostic push |
| 49 |
# pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 50 |
#endif |
| 51 |
status = sixel_decode(sixel, |
| 52 |
(int)strlen((char *)sixel), |
| 53 |
&pixels, |
| 54 |
&width, |
| 55 |
&height, |
| 56 |
&palette, |
| 57 |
&ncolors, |
| 58 |
fail_palette_malloc); |
| 59 |
#if defined(__GNUC__) || defined(__clang__) |
| 60 |
# pragma GCC diagnostic pop |
| 61 |
#endif |
| 62 |
|
| 63 |
free(pixels); |
| 64 |
free(palette); |
| 65 |
|
| 66 |
return status == SIXEL_BAD_ALLOCATION ? 0: 1; |
| 67 |
} |