forked from leftypol/leftypol
PngExifReader.php: add maximum chunk limit
This commit is contained in:
parent
7d8374a45d
commit
83bf65e9be
1 changed files with 3 additions and 2 deletions
|
@ -4,7 +4,8 @@ namespace Vichan\Data\Driver\Metadata;
|
||||||
|
|
||||||
class PngExifReader implements ExifReader {
|
class PngExifReader implements ExifReader {
|
||||||
// Chunks larger than this will be ignored.
|
// Chunks larger than this will be ignored.
|
||||||
private const MAX_CHUNK_SIZE = 1048576; // 1 MB
|
private const MAX_CHUNK_SIZE = 1048576; // 1 MB.
|
||||||
|
private const MAX_CHUNK_COUNT = 32; // 1 MB
|
||||||
private const ORIENTATION_TAG_ID = 0x0112;
|
private const ORIENTATION_TAG_ID = 0x0112;
|
||||||
// Exif data type identifier.
|
// Exif data type identifier.
|
||||||
private const TYPE_SHORT = 0x3;
|
private const TYPE_SHORT = 0x3;
|
||||||
|
@ -111,7 +112,7 @@ class PngExifReader implements ExifReader {
|
||||||
// Loop through the PNG's chunks. Byte 0-3 is length, Byte 4-7 is type.
|
// Loop through the PNG's chunks. Byte 0-3 is length, Byte 4-7 is type.
|
||||||
$chunkHeader = \fread($fd, 8);
|
$chunkHeader = \fread($fd, 8);
|
||||||
|
|
||||||
while ($chunkHeader) {
|
for ($i = 0; $chunkHeader && $i < self::MAX_CHUNK_COUNT; $i++) {
|
||||||
// Extract length and type from binary data.
|
// Extract length and type from binary data.
|
||||||
$chunk = @\unpack('Nsize/a4type', $chunkHeader);
|
$chunk = @\unpack('Nsize/a4type', $chunkHeader);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue