summaryrefslogtreecommitdiff
path: root/ext/gd/gd_compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/gd/gd_compat.c')
-rw-r--r--ext/gd/gd_compat.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/ext/gd/gd_compat.c b/ext/gd/gd_compat.c
new file mode 100644
index 0000000000..dc6a95ae11
--- /dev/null
+++ b/ext/gd/gd_compat.c
@@ -0,0 +1,63 @@
+#include "php_config.h"
+
+#ifdef HAVE_GD_PNG
+/* needs to be first */
+# include <png.h>
+#endif
+
+#ifdef HAVE_GD_JPG
+# include <jpeglib.h>
+#endif
+
+#include "gd_compat.h"
+#include "php.h"
+
+#ifdef HAVE_GD_JPG
+int gdJpegGetVersionInt()
+{
+ return JPEG_LIB_VERSION;
+}
+
+const char * gdJpegGetVersionString()
+{
+ switch(JPEG_LIB_VERSION) {
+ case 62:
+ return "6b";
+ break;
+
+ case 70:
+ return "7";
+ break;
+
+ case 80:
+ return "8";
+ break;
+
+ default:
+ return "unknown";
+ }
+}
+#endif
+
+#ifdef HAVE_GD_PNG
+const char * gdPngGetVersionString()
+{
+ return PNG_LIBPNG_VER_STRING;
+}
+#endif
+
+int overflow2(int a, int b)
+{
+ TSRMLS_FETCH();
+
+ if(a <= 0 || b <= 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "gd warning: one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully\n");
+ return 1;
+ }
+ if(a > INT_MAX / b) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "gd warning: product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully\n");
+ return 1;
+ }
+ return 0;
+}
+