xref: /PHP-8.1/ext/gd/libgd/gd_security.c (revision d1764ca3)
1 /*
2    * gd_security.c
3    *
4    * Implements buffer overflow check routines.
5    *
6    * Written 2004, Phil Knirsch.
7    * Based on netpbm fixes by Alan Cox.
8    *
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <limits.h>
18 #include "gd.h"
19 #include "gd_errors.h"
20 
overflow2(int a,int b)21 int overflow2(int a, int b)
22 {
23 	if(a <= 0 || b <= 0) {
24 		gd_error("One parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
25 		return 1;
26 	}
27 	if(a > INT_MAX / b) {
28 		gd_error("Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
29 		return 1;
30 	}
31 	return 0;
32 }
33