imagepng_nullbyte_injection.phpt 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Testing null byte injection in imagepng
  3. --CLEAN--
  4. $tempdir = sys_get_temp_dir(). '/php-gdtest';
  5. foreach (glob($tempdir . "/test*") as $file ) { unlink($file); }
  6. rmdir($tempdir);
  7. --SKIPIF--
  8. <?php
  9. if(!extension_loaded('gd')){ die('skip gd extension not available'); }
  10. $support = gd_info();
  11. if (!isset($support['PNG Support']) || $support['PNG Support'] === false) {
  12. print 'skip png support not available';
  13. }
  14. ?>
  15. --FILE--
  16. <?php
  17. $image = imagecreate(1,1);// 1px image
  18. $tempdir = sys_get_temp_dir(). '/php-gdtest';
  19. if (!file_exists($tempdir) && !is_dir($tempdir)) {
  20. mkdir ($tempdir, 0777, true);
  21. }
  22. $userinput = "1\0"; // from post or get data
  23. $temp = $tempdir. "/test" . $userinput .".tmp";
  24. echo "\nimagepng TEST\n";
  25. imagepng($image, $temp);
  26. var_dump(file_exists($tempdir. "/test1"));
  27. var_dump(file_exists($tempdir. "/test1.tmp"));
  28. foreach (glob($tempdir . "/test*") as $file ) { unlink($file); }
  29. --EXPECTF--
  30. imagepng TEST
  31. Warning: imagepng(): Invalid 2nd parameter, filename must not contain null bytes in %s on line %d
  32. bool(false)
  33. bool(false)