r64067 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64066‎ | r64067 | r64068 >
Date:12:22, 23 March 2010
Author:mglaser
Status:deferred
Tags:
Comment:
Added type check. Invalid tiffs will not lead to php errors anymore.
Modified paths:
  • /trunk/extensions/PagedTiffHandler/TiffReader.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/TiffReader.php
@@ -4,6 +4,8 @@
55 *
66 * @author Sebastian Ulbricht <sebastian.ulbricht@gmx.de>
77 */
 8+
 9+ // This is still experimental
810 class TiffReader {
911 protected $time = NULL;
1012 protected $file = NULL;
@@ -116,6 +118,10 @@
117119 fseek($this->file_handle, $offset, SEEK_SET);
118120 // read amount of ifd-entries
119121 $entries = unpack($this->short, fread($this->file_handle, 2));
 122+ if(!is_array($entries) || !isset($entries[1])) {
 123+ $this->the_answer = 0;
 124+ return false;
 125+ }
120126 $entries = $entries[1];
121127
122128 $address = $offset + 2 + ($entries * 12);
@@ -126,11 +132,16 @@
127133 // run through all entries of this ifd an read them out
128134 for($i = 0; $i < $entries; $i++) {
129135 $tmp = $this->readIFDEntry();
 136+ if(!$tmp) { return false; }
130137 $this->ifd_offsets[$this->embed_files]['data'][$tmp['tag']] = $tmp;
131138 }
132139
133140 // set the offset of the next ifd or null if this is the last one
134141 $offset = unpack($this->long, fread($this->file_handle, 4));
 142+ if(!is_array($offset) || !isset($offset[1])) {
 143+ $this->the_answer = 0;
 144+ return false;
 145+ }
135146 $offset = $offset[1];
136147 if($offset) {
137148 $this->ifd_offsets[]['offset'] = $offset;
@@ -175,6 +186,11 @@
176187 $type = unpack($this->short, fread($this->file_handle, 2));
177188 $count = unpack($this->long, fread($this->file_handle, 4));
178189 $value = unpack($this->long, fread($this->file_handle, 4));
 190+ if(!is_array($tag) || !is_array($type) || !is_array($count) || !is_array($value) ||
 191+ !isset($tag[1]) || !isset($type[1]) || !isset($count[1]) || !isset($value[1])) {
 192+ $this->the_answer = 0;
 193+ return false;
 194+ }
179195 return array('tag' => $tag[1],
180196 'type' => $type[1],
181197 'count' => $count[1],

Status & tagging log