55 $showXMP = XMPReader::isSupported();
68 if ( !file_exists( $filename ) || is_dir( $filename ) ) {
72 $fh = fopen( $filename,
"rb" );
78 $buffer = fread( $fh, 2 );
79 if ( $buffer !==
"\xFF\xD8" ) {
82 while ( !feof( $fh ) ) {
83 $buffer = fread( $fh, 1 );
85 if ( $segmentCount > self::MAX_JPEG_SEGMENTS ) {
88 while ( $buffer !==
"\xFF" && !feof( $fh ) ) {
91 $buffer = fread( $fh, 1 );
94 $buffer = fread( $fh, 1 );
95 while ( $buffer ===
"\xFF" && !feof( $fh ) ) {
97 $buffer = fread( $fh, 1 );
99 if ( $buffer ===
"\xFE" ) {
103 $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
104 UtfNormal\Validator::quickIsNFCVerify( $com );
107 if ( $com !== $oldCom ) {
108 AtEase::suppressWarnings();
109 $com = $oldCom = iconv(
'windows-1252',
'UTF-8//IGNORE', $oldCom );
110 AtEase::restoreWarnings();
114 UtfNormal\Validator::quickIsNFCVerify( $com );
115 if ( $com === $oldCom ) {
116 $segments[
"COM"][] = $oldCom;
118 wfDebug( __METHOD__ .
" Ignoring JPEG comment as is garbage." );
120 } elseif ( $buffer ===
"\xE1" ) {
123 $temp = self::jpegExtractMarker( $fh );
125 if ( substr( $temp, 0, 29 ) ===
"http://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
127 $segments[
"XMP"] = trim( substr( $temp, 29 ) );
128 } elseif ( substr( $temp, 0, 35 ) ===
"http://ns.adobe.com/xmp/extension/\x00" && $showXMP ) {
130 $segments[
"XMP_ext"][] = trim( substr( $temp, 35 ) );
131 } elseif ( substr( $temp, 0, 29 ) ===
"XMP\x00://ns.adobe.com/xap/1.0/\x00" && $showXMP ) {
136 $segments[
"XMP"] = trim( substr( $temp, 29 ) );
137 wfDebug( __METHOD__ .
' Found XMP section with wrong app identifier '
138 .
"Using anyways." );
139 } elseif ( substr( $temp, 0, 6 ) ===
"Exif\0\0" ) {
143 $byteOrderMarker = substr( $temp, 6, 2 );
144 if ( $byteOrderMarker ===
'MM' ) {
145 $segments[
'byteOrder'] =
'BE';
146 } elseif ( $byteOrderMarker ===
'II' ) {
147 $segments[
'byteOrder'] =
'LE';
149 wfDebug( __METHOD__ .
" Invalid byte ordering?!" );
152 } elseif ( $buffer ===
"\xED" ) {
154 $temp = self::jpegExtractMarker( $fh );
155 if ( substr( $temp, 0, 14 ) ===
"Photoshop 3.0\x00" ) {
156 $segments[
"PSIR"][] = $temp;
158 } elseif ( $buffer ===
"\xD9" || $buffer ===
"\xDA" ) {
161 } elseif ( in_array( $buffer, [
162 "\xC0",
"\xC1",
"\xC2",
"\xC3",
"\xC5",
"\xC6",
"\xC7",
163 "\xC9",
"\xCA",
"\xCB",
"\xCD",
"\xCE",
"\xCF" ] )
166 $temp = self::jpegExtractMarker( $fh );
168 $segments[
"SOF"] = StringUtils::unpack(
'Cbits/nheight/nwidth/Ccomponents', $temp );
175 $size = StringUtils::unpack(
"nint", fread( $fh, 2 ), 2 );
179 if ( $size[
'int'] < 2 ) {
184 fseek( $fh, $size[
'int'] - 2, SEEK_CUR );
232 public static function doPSIR( $app13 ) {
243 $appLen = strlen( $app13 );
248 while ( $offset + 12 <= $appLen ) {
250 if ( substr( $app13, $offset, 4 ) !==
'8BIM' ) {
257 $id = substr( $app13, $offset, 2 );
268 $lenName = ord( substr( $app13, $offset, 1 ) ) + 1;
270 if ( $lenName % 2 === 1 ) {
277 $lenData = StringUtils::unpack(
'Nlen', substr( $app13, $offset, 4 ), 4 );
284 if ( $lenData[
'len'] < 0 ) {
291 if ( $lenData[
'len'] + $offset > $appLen ) {
293 .
"; offset=$offset; total length=$appLen)" );
300 $realHash = md5( substr( $app13, $offset, $lenData[
'len'] ),
true );
303 $recordedHash = substr( $app13, $offset, $lenData[
'len'] );
310 if ( $lenData[
'len'] % 2 === 1 ) {
313 $offset += $lenData[
'len'];
316 if ( !$realHash || !$recordedHash ) {
317 return 'iptc-no-hash';
319 if ( $realHash === $recordedHash ) {
320 return 'iptc-good-hash';
323 return 'iptc-bad-hash';