Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- GH-10834 (exif_read_data() cannot read smaller stream wrapper chunk sizes) --EXTE..

Decoded Output download

--TEST--
GH-10834 (exif_read_data() cannot read smaller stream wrapper chunk sizes)
--EXTENSIONS--
exif
--FILE--
<?php
class VariableStream {
	private $data;
	private $position;
	public $context;

	function stream_close() {
		return true;
	}

	function stream_eof() {
		return $this->position >= strlen($this->data);
	}

	function stream_open($path, $mode, $options, &$opened_path) {
		$this->position = 0;
		$this->data = file_get_contents(__DIR__.'/bug50845.jpg');
		return true;
	}

	function stream_seek($offset, $whence) {
		switch ($whence) {
			case SEEK_SET:
				if ($offset < strlen($this->data) && $offset >= 0) {
					$this->position = $offset;
					return true;
				} else {
					return false;
				}
				break;
			case SEEK_CUR:
				if ($offset >= 0) {
					$this->position += $offset;
					return true;
				} else {
					return false;
				}
				break;
			case SEEK_END:
				if (strlen($this->data) + $offset >= 0) {
					$this->position = strlen($this->data) + $offset;
					return true;
				} else {
					return false;
				}
				break;
			default:
				return false;
		}
	}

	function stream_read($count) {
		$ret = substr($this->data, $this->position, $count);
		$this->position += strlen($ret);
		return $ret;
	}

	function stream_tell() {
		return $this->position;
	}
}

stream_wrapper_register('var', 'VariableStream');

$fp = fopen('var://myvar', 'rb');

stream_set_chunk_size($fp, 10);
$headers = exif_read_data($fp);
var_dump(is_array($headers));

fclose($fp);
?>
--EXPECT--
bool(true)

Did this file decode correctly?

Original Code

--TEST--
GH-10834 (exif_read_data() cannot read smaller stream wrapper chunk sizes)
--EXTENSIONS--
exif
--FILE--
<?php
class VariableStream {
	private $data;
	private $position;
	public $context;

	function stream_close() {
		return true;
	}

	function stream_eof() {
		return $this->position >= strlen($this->data);
	}

	function stream_open($path, $mode, $options, &$opened_path) {
		$this->position = 0;
		$this->data = file_get_contents(__DIR__.'/bug50845.jpg');
		return true;
	}

	function stream_seek($offset, $whence) {
		switch ($whence) {
			case SEEK_SET:
				if ($offset < strlen($this->data) && $offset >= 0) {
					$this->position = $offset;
					return true;
				} else {
					return false;
				}
				break;
			case SEEK_CUR:
				if ($offset >= 0) {
					$this->position += $offset;
					return true;
				} else {
					return false;
				}
				break;
			case SEEK_END:
				if (strlen($this->data) + $offset >= 0) {
					$this->position = strlen($this->data) + $offset;
					return true;
				} else {
					return false;
				}
				break;
			default:
				return false;
		}
	}

	function stream_read($count) {
		$ret = substr($this->data, $this->position, $count);
		$this->position += strlen($ret);
		return $ret;
	}

	function stream_tell() {
		return $this->position;
	}
}

stream_wrapper_register('var', 'VariableStream');

$fp = fopen('var://myvar', 'rb');

stream_set_chunk_size($fp, 10);
$headers = exif_read_data($fp);
var_dump(is_array($headers));

fclose($fp);
?>
--EXPECT--
bool(true)

Function Calls

None

Variables

None

Stats

MD5 25cd969771fc42f0d56bed6c4523ffa3
Eval Count 0
Decode Time 93 ms