imagegd_nullbyte_injection.phpt 909 B

12345678910111213141516171819202122232425262728293031323334
  1. --TEST--
  2. Testing null byte injection in imagegd
  3. --SKIPIF--
  4. <?php
  5. if(!extension_loaded('gd')){ die('skip gd extension not available'); }
  6. ?>
  7. --CLEAN--
  8. $tempdir = sys_get_temp_dir(). '/php-gdtest';
  9. foreach (glob($tempdir . "/test*") as $file ) { unlink($file); }
  10. rmdir($tempdir);
  11. --FILE--
  12. <?php
  13. $image = imagecreate(1,1);// 1px image
  14. $tempdir = sys_get_temp_dir(). '/php-gdtest';
  15. if (!file_exists($tempdir) && !is_dir($tempdir)) {
  16. mkdir ($tempdir, 0777, true);
  17. }
  18. $userinput = "1\0"; // from post or get data
  19. $temp = $tempdir. "/test" . $userinput .".tmp";
  20. echo "\nimagegd TEST\n";
  21. imagegd($image, $temp);
  22. var_dump(file_exists($tempdir. "/test1"));
  23. var_dump(file_exists($tempdir. "/test1.tmp"));
  24. foreach (glob($tempdir . "/test*") as $file ) { unlink($file); }
  25. --EXPECTF--
  26. imagegd TEST
  27. Warning: imagegd() expects parameter 2 to be a valid path, string given in %s on line %d
  28. bool(false)
  29. bool(false)