gd_compat.c 1.1 KB

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