xref: /PHP-7.3/ext/gd/gd_compat.c (revision 1c850bfc)
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #else
4 #include "php_config.h"
5 #endif
6 
7 #ifdef HAVE_GD_PNG
8 /* needs to be first */
9 # include <png.h>
10 #endif
11 
12 #ifdef HAVE_GD_JPG
13 # include <jpeglib.h>
14 #endif
15 
16 #include "gd_compat.h"
17 #include "php.h"
18 
19 #ifdef HAVE_GD_JPG
gdJpegGetVersionString()20 const char * gdJpegGetVersionString()
21 {
22 	switch(JPEG_LIB_VERSION) {
23 		case 62:
24 			return "6b";
25 			break;
26 
27 		case 70:
28 			return "7";
29 			break;
30 
31 		case 80:
32 			return "8";
33 			break;
34 
35 		default:
36 			return "unknown";
37 	}
38 }
39 #endif
40 
41 #ifdef HAVE_GD_PNG
gdPngGetVersionString()42 const char * gdPngGetVersionString()
43 {
44 	return PNG_LIBPNG_VER_STRING;
45 }
46 #endif
47 
overflow2(int a,int b)48 int overflow2(int a, int b)
49 {
50 
51 	if(a <= 0 || b <= 0) {
52 		php_error_docref(NULL, E_WARNING, "one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
53 		return 1;
54 	}
55 	if(a > INT_MAX / b) {
56 		php_error_docref(NULL, E_WARNING, "product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
57 		return 1;
58 	}
59 	return 0;
60 }
61