xref: /PHP-7.0/ext/gd/gd_compat.c (revision b42eb16c)
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
gdJpegGetVersionInt()20 int gdJpegGetVersionInt()
21 {
22 	return JPEG_LIB_VERSION;
23 }
24 
gdJpegGetVersionString()25 const char * gdJpegGetVersionString()
26 {
27 	switch(JPEG_LIB_VERSION) {
28 		case 62:
29 			return "6b";
30 			break;
31 
32 		case 70:
33 			return "7";
34 			break;
35 
36 		case 80:
37 			return "8";
38 			break;
39 
40 		default:
41 			return "unknown";
42 	}
43 }
44 #endif
45 
46 #ifdef HAVE_GD_PNG
gdPngGetVersionString()47 const char * gdPngGetVersionString()
48 {
49 	return PNG_LIBPNG_VER_STRING;
50 }
51 #endif
52 
overflow2(int a,int b)53 int overflow2(int a, int b)
54 {
55 
56 	if(a <= 0 || b <= 0) {
57 		php_error_docref(NULL, E_WARNING, "gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
58 		return 1;
59 	}
60 	if(a > INT_MAX / b) {
61 		php_error_docref(NULL, E_WARNING, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
62 		return 1;
63 	}
64 	return 0;
65 }
66 
67