bug72339.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Bug #72339 Integer Overflow in _gd2GetHeader() resulting in heap overflow
  3. --EXTENSIONS--
  4. gd
  5. --SKIPIF--
  6. <?php
  7. if (!function_exists("imagecreatefromgd2")) print "skip";
  8. if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.2', '<')) {
  9. die("skip test requires GD 2.2.2 or higher");
  10. }
  11. ?>
  12. --FILE--
  13. <?php
  14. $fname = __DIR__ . DIRECTORY_SEPARATOR . "bug72339.gd";
  15. $fh = fopen($fname, "w");
  16. fwrite($fh, "gd2\x00");
  17. fwrite($fh, pack("n", 2));
  18. fwrite($fh, pack("n", 1));
  19. fwrite($fh, pack("n", 1));
  20. fwrite($fh, pack("n", 0x40));
  21. fwrite($fh, pack("n", 2));
  22. fwrite($fh, pack("n", 0x5AA0)); // Chunks Wide
  23. fwrite($fh, pack("n", 0x5B00)); // Chunks Vertically
  24. fwrite($fh, str_repeat("\x41\x41\x41\x41", 0x1000000)); // overflow data
  25. fclose($fh);
  26. $im = imagecreatefromgd2($fname);
  27. if ($im) {
  28. imagedestroy($im);
  29. }
  30. unlink($fname);
  31. ?>
  32. --EXPECTF--
  33. Warning: imagecreatefromgd2(): Product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully
  34. in %sbug72339.php on line %d
  35. Warning: imagecreatefromgd2(): "%sbug72339.gd" is not a valid GD2 file in %sbug72339.php on line %d