|
|
16aa34 |
commit 78a56b21340157775be2462a19276b4d31d2bd01
|
|
|
16aa34 |
Author: Andrea Mazzoleni <amadvance@gmail.com>
|
|
|
16aa34 |
Date: Fri Jan 4 20:49:25 2019 +0100
|
|
|
16aa34 |
|
|
|
16aa34 |
Fix a buffer overflow caused by invalid images
|
|
|
16aa34 |
|
|
|
16aa34 |
diff --git a/lib/png.c b/lib/png.c
|
|
|
16aa34 |
index 0939a5a..cbf140b 100644
|
|
|
16aa34 |
--- a/lib/png.c
|
|
|
16aa34 |
+++ b/lib/png.c
|
|
|
16aa34 |
@@ -603,6 +603,7 @@ adv_error adv_png_read_ihdr(
|
|
|
16aa34 |
unsigned pixel;
|
|
|
16aa34 |
unsigned width;
|
|
|
16aa34 |
unsigned width_align;
|
|
|
16aa34 |
+ unsigned scanline;
|
|
|
16aa34 |
unsigned height;
|
|
|
16aa34 |
unsigned depth;
|
|
|
16aa34 |
int r;
|
|
|
16aa34 |
@@ -719,9 +720,23 @@ adv_error adv_png_read_ihdr(
|
|
|
16aa34 |
goto err_ptr;
|
|
|
16aa34 |
}
|
|
|
16aa34 |
|
|
|
16aa34 |
- *dat_size = height * (width_align * pixel + 1);
|
|
|
16aa34 |
+ /* check for overflow */
|
|
|
16aa34 |
+ if (pixel == 0 || width_align >= UINT_MAX / pixel) {
|
|
|
16aa34 |
+ error_set("Invalid image size");
|
|
|
16aa34 |
+ goto err_ptr;
|
|
|
16aa34 |
+ }
|
|
|
16aa34 |
+
|
|
|
16aa34 |
+ scanline = width_align * pixel + 1;
|
|
|
16aa34 |
+
|
|
|
16aa34 |
+ /* check for overflow */
|
|
|
16aa34 |
+ if (scanline == 0 || height >= UINT_MAX / scanline) {
|
|
|
16aa34 |
+ error_set("Invalid image size");
|
|
|
16aa34 |
+ goto err_ptr;
|
|
|
16aa34 |
+ }
|
|
|
16aa34 |
+
|
|
|
16aa34 |
+ *dat_size = height * scanline;
|
|
|
16aa34 |
*dat_ptr = malloc(*dat_size);
|
|
|
16aa34 |
- *pix_scanline = width_align * pixel + 1;
|
|
|
16aa34 |
+ *pix_scanline = scanline;
|
|
|
16aa34 |
*pix_ptr = *dat_ptr + 1;
|
|
|
16aa34 |
|
|
|
16aa34 |
z.zalloc = 0;
|
|
|
16aa34 |
diff -up advancecomp-1.15/portable.h.me advancecomp-1.15/portable.h
|
|
|
16aa34 |
--- advancecomp-1.15/portable.h.me 2019-05-17 15:15:08.109528451 +0200
|
|
|
16aa34 |
+++ advancecomp-1.15/portable.h 2019-05-17 15:15:38.318620937 +0200
|
|
|
16aa34 |
@@ -39,6 +39,7 @@ extern "C" {
|
|
|
16aa34 |
#include <assert.h>
|
|
|
16aa34 |
#include <errno.h>
|
|
|
16aa34 |
#include <signal.h>
|
|
|
16aa34 |
+#include <limits.h>
|
|
|
16aa34 |
|
|
|
16aa34 |
#if HAVE_UNISTD_H
|
|
|
16aa34 |
#include <unistd.h>
|