1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.txt |
11 : | If you did not receive a copy of the PHP license and are unable to |
12 : | obtain it through the world-wide-web, please send a note to |
13 : | license@php.net so we can mail you a copy immediately. |
14 : +----------------------------------------------------------------------+
15 : | Authors: Rasmus Lerdorf <rasmus@php.net> |
16 : | Marcus Boerger <helly@php.net> |
17 : +----------------------------------------------------------------------+
18 : */
19 :
20 : /* $Id: exif.c 290173 2009-11-03 17:11:09Z guenter $ */
21 :
22 : /* ToDos
23 : *
24 : * See if example images from http://www.exif.org have illegal
25 : * thumbnail sizes or if code is corrupt.
26 : * Create/Update exif headers.
27 : * Create/Remove/Update image thumbnails.
28 : */
29 :
30 : /* Security
31 : *
32 : * At current time i do not see any security problems but a potential
33 : * attacker could generate an image with recursive ifd pointers...(Marcus)
34 : */
35 :
36 : #ifdef HAVE_CONFIG_H
37 : #include "config.h"
38 : #endif
39 :
40 : #include "php.h"
41 : #include "ext/standard/file.h"
42 :
43 : #if HAVE_EXIF
44 :
45 : /* When EXIF_DEBUG is defined the module generates a lot of debug messages
46 : * that help understanding what is going on. This can and should be used
47 : * while extending the module as it shows if you are at the right position.
48 : * You are always considered to have a copy of TIFF6.0 and EXIF2.10 standard.
49 : */
50 : #undef EXIF_DEBUG
51 :
52 : #ifdef EXIF_DEBUG
53 : #define EXIFERR_DC , const char *_file, size_t _line TSRMLS_DC
54 : #define EXIFERR_CC , __FILE__, __LINE__ TSRMLS_CC
55 : #else
56 : #define EXIFERR_DC TSRMLS_DC
57 : #define EXIFERR_CC TSRMLS_CC
58 : #endif
59 :
60 : #undef EXIF_JPEG2000
61 :
62 : #include "php_exif.h"
63 : #include <math.h>
64 : #include "php_ini.h"
65 : #include "ext/standard/php_string.h"
66 : #include "ext/standard/php_image.h"
67 : #include "ext/standard/info.h"
68 :
69 : #if defined(PHP_WIN32) || (HAVE_MBSTRING && !defined(COMPILE_DL_MBSTRING))
70 : #define EXIF_USE_MBSTRING 1
71 : #else
72 : #define EXIF_USE_MBSTRING 0
73 : #endif
74 :
75 : #if EXIF_USE_MBSTRING
76 : #include "ext/mbstring/mbstring.h"
77 : #endif
78 :
79 : /* needed for ssize_t definition */
80 : #include <sys/types.h>
81 :
82 : typedef unsigned char uchar;
83 :
84 : #ifndef safe_emalloc
85 : # define safe_emalloc(a,b,c) emalloc((a)*(b)+(c))
86 : #endif
87 : #ifndef safe_erealloc
88 : # define safe_erealloc(p,a,b,c) erealloc(p, (a)*(b)+(c))
89 : #endif
90 :
91 : #ifndef TRUE
92 : # define TRUE 1
93 : # define FALSE 0
94 : #endif
95 :
96 : #ifndef max
97 : # define max(a,b) ((a)>(b) ? (a) : (b))
98 : #endif
99 :
100 : #define EFREE_IF(ptr) if (ptr) efree(ptr)
101 :
102 : #define MAX_IFD_NESTING_LEVEL 100
103 :
104 : /* {{{ arginfo */
105 : static
106 : ZEND_BEGIN_ARG_INFO(arginfo_exif_tagname, 0)
107 : ZEND_ARG_INFO(0, index)
108 : ZEND_END_ARG_INFO()
109 :
110 : static
111 : ZEND_BEGIN_ARG_INFO_EX(arginfo_exif_read_data, 0, 0, 1)
112 : ZEND_ARG_INFO(0, filename)
113 : ZEND_ARG_INFO(0, sections_needed)
114 : ZEND_ARG_INFO(0, sub_arrays)
115 : ZEND_ARG_INFO(0, read_thumbnail)
116 : ZEND_END_ARG_INFO()
117 :
118 : static
119 : ZEND_BEGIN_ARG_INFO_EX(arginfo_exif_thumbnail, 0, 0, 1)
120 : ZEND_ARG_INFO(0, filename)
121 : ZEND_ARG_INFO(1, width)
122 : ZEND_ARG_INFO(1, height)
123 : ZEND_ARG_INFO(1, imagetype)
124 : ZEND_END_ARG_INFO()
125 :
126 : static
127 : ZEND_BEGIN_ARG_INFO(arginfo_exif_imagetype, 0)
128 : ZEND_ARG_INFO(0, imagefile)
129 : ZEND_END_ARG_INFO()
130 :
131 : /* }}} */
132 :
133 : /* {{{ exif_functions[]
134 : */
135 : zend_function_entry exif_functions[] = {
136 : PHP_FE(exif_read_data, arginfo_exif_read_data)
137 : PHP_FALIAS(read_exif_data, exif_read_data, arginfo_exif_read_data)
138 : PHP_FE(exif_tagname, arginfo_exif_tagname)
139 : PHP_FE(exif_thumbnail, arginfo_exif_thumbnail)
140 : PHP_FE(exif_imagetype, arginfo_exif_imagetype)
141 : {NULL, NULL, NULL}
142 : };
143 : /* }}} */
144 :
145 : #define EXIF_VERSION "1.4 $Id: exif.c 290173 2009-11-03 17:11:09Z guenter $"
146 :
147 : /* {{{ PHP_MINFO_FUNCTION
148 : */
149 : PHP_MINFO_FUNCTION(exif)
150 6 : {
151 6 : php_info_print_table_start();
152 6 : php_info_print_table_row(2, "EXIF Support", "enabled");
153 6 : php_info_print_table_row(2, "EXIF Version", EXIF_VERSION);
154 6 : php_info_print_table_row(2, "Supported EXIF Version", "0220");
155 6 : php_info_print_table_row(2, "Supported filetypes", "JPEG,TIFF");
156 6 : php_info_print_table_end();
157 6 : }
158 : /* }}} */
159 :
160 : ZEND_BEGIN_MODULE_GLOBALS(exif)
161 : char * encode_unicode;
162 : char * decode_unicode_be;
163 : char * decode_unicode_le;
164 : char * encode_jis;
165 : char * decode_jis_be;
166 : char * decode_jis_le;
167 : ZEND_END_MODULE_GLOBALS(exif)
168 :
169 : ZEND_DECLARE_MODULE_GLOBALS(exif)
170 :
171 : #ifdef ZTS
172 : #define EXIF_G(v) TSRMG(exif_globals_id, zend_exif_globals *, v)
173 : #else
174 : #define EXIF_G(v) (exif_globals.v)
175 : #endif
176 :
177 : /* {{{ PHP_INI
178 : */
179 :
180 : ZEND_INI_MH(OnUpdateEncode)
181 27130 : {
182 : #if EXIF_USE_MBSTRING
183 27130 : if (new_value && strlen(new_value) && !php_mb_check_encoding_list(new_value TSRMLS_CC)) {
184 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value);
185 0 : return FAILURE;
186 : }
187 : #endif
188 27130 : return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
189 : }
190 :
191 : ZEND_INI_MH(OnUpdateDecode)
192 54260 : {
193 : #if EXIF_USE_MBSTRING
194 54260 : if (!php_mb_check_encoding_list(new_value TSRMLS_CC)) {
195 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal encoding ignored: '%s'", new_value);
196 0 : return FAILURE;
197 : }
198 : #endif
199 54260 : return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
200 : }
201 :
202 : PHP_INI_BEGIN()
203 : STD_PHP_INI_ENTRY("exif.encode_unicode", "ISO-8859-15", PHP_INI_ALL, OnUpdateEncode, encode_unicode, zend_exif_globals, exif_globals)
204 : STD_PHP_INI_ENTRY("exif.decode_unicode_motorola", "UCS-2BE", PHP_INI_ALL, OnUpdateDecode, decode_unicode_be, zend_exif_globals, exif_globals)
205 : STD_PHP_INI_ENTRY("exif.decode_unicode_intel", "UCS-2LE", PHP_INI_ALL, OnUpdateDecode, decode_unicode_le, zend_exif_globals, exif_globals)
206 : STD_PHP_INI_ENTRY("exif.encode_jis", "", PHP_INI_ALL, OnUpdateEncode, encode_jis, zend_exif_globals, exif_globals)
207 : STD_PHP_INI_ENTRY("exif.decode_jis_motorola", "JIS", PHP_INI_ALL, OnUpdateDecode, decode_jis_be, zend_exif_globals, exif_globals)
208 : STD_PHP_INI_ENTRY("exif.decode_jis_intel", "JIS", PHP_INI_ALL, OnUpdateDecode, decode_jis_le, zend_exif_globals, exif_globals)
209 : PHP_INI_END()
210 : /* }}} */
211 :
212 : /* {{{ PHP_GINIT_FUNCTION
213 : */
214 : static PHP_GINIT_FUNCTION(exif)
215 13565 : {
216 13565 : exif_globals->encode_unicode = NULL;
217 13565 : exif_globals->decode_unicode_be = NULL;
218 13565 : exif_globals->decode_unicode_le = NULL;
219 13565 : exif_globals->encode_jis = NULL;
220 13565 : exif_globals->decode_jis_be = NULL;
221 13565 : exif_globals->decode_jis_le = NULL;
222 13565 : }
223 : /* }}} */
224 :
225 : /* {{{ PHP_MINIT_FUNCTION(exif)
226 : Get the size of an image as 4-element array */
227 : PHP_MINIT_FUNCTION(exif)
228 13565 : {
229 13565 : REGISTER_INI_ENTRIES();
230 13565 : REGISTER_LONG_CONSTANT("EXIF_USE_MBSTRING", EXIF_USE_MBSTRING, CONST_CS | CONST_PERSISTENT);
231 13565 : return SUCCESS;
232 : }
233 : /* }}} */
234 :
235 : /* {{{ PHP_MSHUTDOWN_FUNCTION
236 : */
237 : PHP_MSHUTDOWN_FUNCTION(exif)
238 13598 : {
239 13598 : UNREGISTER_INI_ENTRIES();
240 13598 : return SUCCESS;
241 : }
242 : /* }}} */
243 :
244 : /* {{{ exif dependencies */
245 : static zend_module_dep exif_module_deps[] = {
246 : ZEND_MOD_REQUIRED("standard")
247 : #if EXIF_USE_MBSTRING
248 : ZEND_MOD_REQUIRED("mbstring")
249 : #endif
250 : {NULL, NULL, NULL}
251 : };
252 : /* }}} */
253 :
254 : /* {{{ exif_module_entry
255 : */
256 : zend_module_entry exif_module_entry = {
257 : STANDARD_MODULE_HEADER_EX, NULL,
258 : exif_module_deps,
259 : "exif",
260 : exif_functions,
261 : PHP_MINIT(exif),
262 : PHP_MSHUTDOWN(exif),
263 : NULL, NULL,
264 : PHP_MINFO(exif),
265 : #if ZEND_MODULE_API_NO >= 20010901
266 : EXIF_VERSION,
267 : #endif
268 : #if ZEND_MODULE_API_NO >= 20060613
269 : PHP_MODULE_GLOBALS(exif),
270 : PHP_GINIT(exif),
271 : NULL,
272 : NULL,
273 : STANDARD_MODULE_PROPERTIES_EX
274 : #else
275 : STANDARD_MODULE_PROPERTIES
276 : #endif
277 : };
278 : /* }}} */
279 :
280 : #ifdef COMPILE_DL_EXIF
281 : ZEND_GET_MODULE(exif)
282 : #endif
283 :
284 : /* {{{ php_strnlen
285 : * get length of string if buffer if less than buffer size or buffer size */
286 191 : static size_t php_strnlen(char* str, size_t maxlen) {
287 191 : size_t len = 0;
288 :
289 191 : if (str && maxlen && *str) {
290 : do {
291 2264 : len++;
292 2264 : } while (--maxlen && *(++str));
293 : }
294 191 : return len;
295 : }
296 : /* }}} */
297 :
298 : /* {{{ error messages
299 : */
300 : static const char * EXIF_ERROR_FILEEOF = "Unexpected end of file reached";
301 : static const char * EXIF_ERROR_CORRUPT = "File structure corrupted";
302 : static const char * EXIF_ERROR_THUMBEOF = "Thumbnail goes IFD boundary or end of file reached";
303 : static const char * EXIF_ERROR_FSREALLOC = "Illegal reallocating of undefined file section";
304 :
305 : #define EXIF_ERRLOG_FILEEOF(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_FILEEOF);
306 : #define EXIF_ERRLOG_CORRUPT(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_CORRUPT);
307 : #define EXIF_ERRLOG_THUMBEOF(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_THUMBEOF);
308 : #define EXIF_ERRLOG_FSREALLOC(ImageInfo) exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s", EXIF_ERROR_FSREALLOC);
309 : /* }}} */
310 :
311 : /* {{{ format description defines
312 : Describes format descriptor
313 : */
314 : static int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
315 : #define NUM_FORMATS 13
316 :
317 : #define TAG_FMT_BYTE 1
318 : #define TAG_FMT_STRING 2
319 : #define TAG_FMT_USHORT 3
320 : #define TAG_FMT_ULONG 4
321 : #define TAG_FMT_URATIONAL 5
322 : #define TAG_FMT_SBYTE 6
323 : #define TAG_FMT_UNDEFINED 7
324 : #define TAG_FMT_SSHORT 8
325 : #define TAG_FMT_SLONG 9
326 : #define TAG_FMT_SRATIONAL 10
327 : #define TAG_FMT_SINGLE 11
328 : #define TAG_FMT_DOUBLE 12
329 : #define TAG_FMT_IFD 13
330 :
331 : #ifdef EXIF_DEBUG
332 : static char *exif_get_tagformat(int format)
333 : {
334 : switch(format) {
335 : case TAG_FMT_BYTE: return "BYTE";
336 : case TAG_FMT_STRING: return "STRING";
337 : case TAG_FMT_USHORT: return "USHORT";
338 : case TAG_FMT_ULONG: return "ULONG";
339 : case TAG_FMT_URATIONAL: return "URATIONAL";
340 : case TAG_FMT_SBYTE: return "SBYTE";
341 : case TAG_FMT_UNDEFINED: return "UNDEFINED";
342 : case TAG_FMT_SSHORT: return "SSHORT";
343 : case TAG_FMT_SLONG: return "SLONG";
344 : case TAG_FMT_SRATIONAL: return "SRATIONAL";
345 : case TAG_FMT_SINGLE: return "SINGLE";
346 : case TAG_FMT_DOUBLE: return "DOUBLE";
347 : case TAG_FMT_IFD: return "IFD";
348 : }
349 : return "*Illegal";
350 : }
351 : #endif
352 :
353 : /* Describes tag values */
354 : #define TAG_GPS_VERSION_ID 0x0000
355 : #define TAG_GPS_LATITUDE_REF 0x0001
356 : #define TAG_GPS_LATITUDE 0x0002
357 : #define TAG_GPS_LONGITUDE_REF 0x0003
358 : #define TAG_GPS_LONGITUDE 0x0004
359 : #define TAG_GPS_ALTITUDE_REF 0x0005
360 : #define TAG_GPS_ALTITUDE 0x0006
361 : #define TAG_GPS_TIME_STAMP 0x0007
362 : #define TAG_GPS_SATELLITES 0x0008
363 : #define TAG_GPS_STATUS 0x0009
364 : #define TAG_GPS_MEASURE_MODE 0x000A
365 : #define TAG_GPS_DOP 0x000B
366 : #define TAG_GPS_SPEED_REF 0x000C
367 : #define TAG_GPS_SPEED 0x000D
368 : #define TAG_GPS_TRACK_REF 0x000E
369 : #define TAG_GPS_TRACK 0x000F
370 : #define TAG_GPS_IMG_DIRECTION_REF 0x0010
371 : #define TAG_GPS_IMG_DIRECTION 0x0011
372 : #define TAG_GPS_MAP_DATUM 0x0012
373 : #define TAG_GPS_DEST_LATITUDE_REF 0x0013
374 : #define TAG_GPS_DEST_LATITUDE 0x0014
375 : #define TAG_GPS_DEST_LONGITUDE_REF 0x0015
376 : #define TAG_GPS_DEST_LONGITUDE 0x0016
377 : #define TAG_GPS_DEST_BEARING_REF 0x0017
378 : #define TAG_GPS_DEST_BEARING 0x0018
379 : #define TAG_GPS_DEST_DISTANCE_REF 0x0019
380 : #define TAG_GPS_DEST_DISTANCE 0x001A
381 : #define TAG_GPS_PROCESSING_METHOD 0x001B
382 : #define TAG_GPS_AREA_INFORMATION 0x001C
383 : #define TAG_GPS_DATE_STAMP 0x001D
384 : #define TAG_GPS_DIFFERENTIAL 0x001E
385 : #define TAG_TIFF_COMMENT 0x00FE /* SHOUDLNT HAPPEN */
386 : #define TAG_NEW_SUBFILE 0x00FE /* New version of subfile tag */
387 : #define TAG_SUBFILE_TYPE 0x00FF /* Old version of subfile tag */
388 : #define TAG_IMAGEWIDTH 0x0100
389 : #define TAG_IMAGEHEIGHT 0x0101
390 : #define TAG_BITS_PER_SAMPLE 0x0102
391 : #define TAG_COMPRESSION 0x0103
392 : #define TAG_PHOTOMETRIC_INTERPRETATION 0x0106
393 : #define TAG_TRESHHOLDING 0x0107
394 : #define TAG_CELL_WIDTH 0x0108
395 : #define TAG_CELL_HEIGHT 0x0109
396 : #define TAG_FILL_ORDER 0x010A
397 : #define TAG_DOCUMENT_NAME 0x010D
398 : #define TAG_IMAGE_DESCRIPTION 0x010E
399 : #define TAG_MAKE 0x010F
400 : #define TAG_MODEL 0x0110
401 : #define TAG_STRIP_OFFSETS 0x0111
402 : #define TAG_ORIENTATION 0x0112
403 : #define TAG_SAMPLES_PER_PIXEL 0x0115
404 : #define TAG_ROWS_PER_STRIP 0x0116
405 : #define TAG_STRIP_BYTE_COUNTS 0x0117
406 : #define TAG_MIN_SAMPPLE_VALUE 0x0118
407 : #define TAG_MAX_SAMPLE_VALUE 0x0119
408 : #define TAG_X_RESOLUTION 0x011A
409 : #define TAG_Y_RESOLUTION 0x011B
410 : #define TAG_PLANAR_CONFIGURATION 0x011C
411 : #define TAG_PAGE_NAME 0x011D
412 : #define TAG_X_POSITION 0x011E
413 : #define TAG_Y_POSITION 0x011F
414 : #define TAG_FREE_OFFSETS 0x0120
415 : #define TAG_FREE_BYTE_COUNTS 0x0121
416 : #define TAG_GRAY_RESPONSE_UNIT 0x0122
417 : #define TAG_GRAY_RESPONSE_CURVE 0x0123
418 : #define TAG_RESOLUTION_UNIT 0x0128
419 : #define TAG_PAGE_NUMBER 0x0129
420 : #define TAG_TRANSFER_FUNCTION 0x012D
421 : #define TAG_SOFTWARE 0x0131
422 : #define TAG_DATETIME 0x0132
423 : #define TAG_ARTIST 0x013B
424 : #define TAG_HOST_COMPUTER 0x013C
425 : #define TAG_PREDICTOR 0x013D
426 : #define TAG_WHITE_POINT 0x013E
427 : #define TAG_PRIMARY_CHROMATICITIES 0x013F
428 : #define TAG_COLOR_MAP 0x0140
429 : #define TAG_HALFTONE_HINTS 0x0141
430 : #define TAG_TILE_WIDTH 0x0142
431 : #define TAG_TILE_LENGTH 0x0143
432 : #define TAG_TILE_OFFSETS 0x0144
433 : #define TAG_TILE_BYTE_COUNTS 0x0145
434 : #define TAG_SUB_IFD 0x014A
435 : #define TAG_INK_SETMPUTER 0x014C
436 : #define TAG_INK_NAMES 0x014D
437 : #define TAG_NUMBER_OF_INKS 0x014E
438 : #define TAG_DOT_RANGE 0x0150
439 : #define TAG_TARGET_PRINTER 0x0151
440 : #define TAG_EXTRA_SAMPLE 0x0152
441 : #define TAG_SAMPLE_FORMAT 0x0153
442 : #define TAG_S_MIN_SAMPLE_VALUE 0x0154
443 : #define TAG_S_MAX_SAMPLE_VALUE 0x0155
444 : #define TAG_TRANSFER_RANGE 0x0156
445 : #define TAG_JPEG_TABLES 0x015B
446 : #define TAG_JPEG_PROC 0x0200
447 : #define TAG_JPEG_INTERCHANGE_FORMAT 0x0201
448 : #define TAG_JPEG_INTERCHANGE_FORMAT_LEN 0x0202
449 : #define TAG_JPEG_RESTART_INTERVAL 0x0203
450 : #define TAG_JPEG_LOSSLESS_PREDICTOR 0x0205
451 : #define TAG_JPEG_POINT_TRANSFORMS 0x0206
452 : #define TAG_JPEG_Q_TABLES 0x0207
453 : #define TAG_JPEG_DC_TABLES 0x0208
454 : #define TAG_JPEG_AC_TABLES 0x0209
455 : #define TAG_YCC_COEFFICIENTS 0x0211
456 : #define TAG_YCC_SUB_SAMPLING 0x0212
457 : #define TAG_YCC_POSITIONING 0x0213
458 : #define TAG_REFERENCE_BLACK_WHITE 0x0214
459 : /* 0x0301 - 0x0302 */
460 : /* 0x0320 */
461 : /* 0x0343 */
462 : /* 0x5001 - 0x501B */
463 : /* 0x5021 - 0x503B */
464 : /* 0x5090 - 0x5091 */
465 : /* 0x5100 - 0x5101 */
466 : /* 0x5110 - 0x5113 */
467 : /* 0x80E3 - 0x80E6 */
468 : /* 0x828d - 0x828F */
469 : #define TAG_COPYRIGHT 0x8298
470 : #define TAG_EXPOSURETIME 0x829A
471 : #define TAG_FNUMBER 0x829D
472 : #define TAG_EXIF_IFD_POINTER 0x8769
473 : #define TAG_ICC_PROFILE 0x8773
474 : #define TAG_EXPOSURE_PROGRAM 0x8822
475 : #define TAG_SPECTRAL_SENSITY 0x8824
476 : #define TAG_GPS_IFD_POINTER 0x8825
477 : #define TAG_ISOSPEED 0x8827
478 : #define TAG_OPTOELECTRIC_CONVERSION_F 0x8828
479 : /* 0x8829 - 0x882b */
480 : #define TAG_EXIFVERSION 0x9000
481 : #define TAG_DATE_TIME_ORIGINAL 0x9003
482 : #define TAG_DATE_TIME_DIGITIZED 0x9004
483 : #define TAG_COMPONENT_CONFIG 0x9101
484 : #define TAG_COMPRESSED_BITS_PER_PIXEL 0x9102
485 : #define TAG_SHUTTERSPEED 0x9201
486 : #define TAG_APERTURE 0x9202
487 : #define TAG_BRIGHTNESS_VALUE 0x9203
488 : #define TAG_EXPOSURE_BIAS_VALUE 0x9204
489 : #define TAG_MAX_APERTURE 0x9205
490 : #define TAG_SUBJECT_DISTANCE 0x9206
491 : #define TAG_METRIC_MODULE 0x9207
492 : #define TAG_LIGHT_SOURCE 0x9208
493 : #define TAG_FLASH 0x9209
494 : #define TAG_FOCAL_LENGTH 0x920A
495 : /* 0x920B - 0x920D */
496 : /* 0x9211 - 0x9216 */
497 : #define TAG_SUBJECT_AREA 0x9214
498 : #define TAG_MAKER_NOTE 0x927C
499 : #define TAG_USERCOMMENT 0x9286
500 : #define TAG_SUB_SEC_TIME 0x9290
501 : #define TAG_SUB_SEC_TIME_ORIGINAL 0x9291
502 : #define TAG_SUB_SEC_TIME_DIGITIZED 0x9292
503 : /* 0x923F */
504 : /* 0x935C */
505 : #define TAG_XP_TITLE 0x9C9B
506 : #define TAG_XP_COMMENTS 0x9C9C
507 : #define TAG_XP_AUTHOR 0x9C9D
508 : #define TAG_XP_KEYWORDS 0x9C9E
509 : #define TAG_XP_SUBJECT 0x9C9F
510 : #define TAG_FLASH_PIX_VERSION 0xA000
511 : #define TAG_COLOR_SPACE 0xA001
512 : #define TAG_COMP_IMAGE_WIDTH 0xA002 /* compressed images only */
513 : #define TAG_COMP_IMAGE_HEIGHT 0xA003
514 : #define TAG_RELATED_SOUND_FILE 0xA004
515 : #define TAG_INTEROP_IFD_POINTER 0xA005 /* IFD pointer */
516 : #define TAG_FLASH_ENERGY 0xA20B
517 : #define TAG_SPATIAL_FREQUENCY_RESPONSE 0xA20C
518 : #define TAG_FOCALPLANE_X_RES 0xA20E
519 : #define TAG_FOCALPLANE_Y_RES 0xA20F
520 : #define TAG_FOCALPLANE_RESOLUTION_UNIT 0xA210
521 : #define TAG_SUBJECT_LOCATION 0xA214
522 : #define TAG_EXPOSURE_INDEX 0xA215
523 : #define TAG_SENSING_METHOD 0xA217
524 : #define TAG_FILE_SOURCE 0xA300
525 : #define TAG_SCENE_TYPE 0xA301
526 : #define TAG_CFA_PATTERN 0xA302
527 : #define TAG_CUSTOM_RENDERED 0xA401
528 : #define TAG_EXPOSURE_MODE 0xA402
529 : #define TAG_WHITE_BALANCE 0xA403
530 : #define TAG_DIGITAL_ZOOM_RATIO 0xA404
531 : #define TAG_FOCAL_LENGTH_IN_35_MM_FILM 0xA405
532 : #define TAG_SCENE_CAPTURE_TYPE 0xA406
533 : #define TAG_GAIN_CONTROL 0xA407
534 : #define TAG_CONTRAST 0xA408
535 : #define TAG_SATURATION 0xA409
536 : #define TAG_SHARPNESS 0xA40A
537 : #define TAG_DEVICE_SETTING_DESCRIPTION 0xA40B
538 : #define TAG_SUBJECT_DISTANCE_RANGE 0xA40C
539 : #define TAG_IMAGE_UNIQUE_ID 0xA420
540 :
541 : /* Olympus specific tags */
542 : #define TAG_OLYMPUS_SPECIALMODE 0x0200
543 : #define TAG_OLYMPUS_JPEGQUAL 0x0201
544 : #define TAG_OLYMPUS_MACRO 0x0202
545 : #define TAG_OLYMPUS_DIGIZOOM 0x0204
546 : #define TAG_OLYMPUS_SOFTWARERELEASE 0x0207
547 : #define TAG_OLYMPUS_PICTINFO 0x0208
548 : #define TAG_OLYMPUS_CAMERAID 0x0209
549 : /* end Olympus specific tags */
550 :
551 : /* Internal */
552 : #define TAG_NONE -1 /* note that -1 <> 0xFFFF */
553 : #define TAG_COMPUTED_VALUE -2
554 : #define TAG_END_OF_LIST 0xFFFD
555 :
556 : /* Values for TAG_PHOTOMETRIC_INTERPRETATION */
557 : #define PMI_BLACK_IS_ZERO 0
558 : #define PMI_WHITE_IS_ZERO 1
559 : #define PMI_RGB 2
560 : #define PMI_PALETTE_COLOR 3
561 : #define PMI_TRANSPARENCY_MASK 4
562 : #define PMI_SEPARATED 5
563 : #define PMI_YCBCR 6
564 : #define PMI_CIELAB 8
565 :
566 : /* }}} */
567 :
568 : /* {{{ TabTable[]
569 : */
570 : typedef const struct {
571 : unsigned short Tag;
572 : char *Desc;
573 : } tag_info_type;
574 :
575 : typedef tag_info_type tag_info_array[];
576 : typedef tag_info_type *tag_table_type;
577 :
578 : #define TAG_TABLE_END \
579 : {TAG_NONE, "No tag value"},\
580 : {TAG_COMPUTED_VALUE, "Computed value"},\
581 : {TAG_END_OF_LIST, ""} /* Important for exif_get_tagname() IF value != "" function result is != false */
582 :
583 : static tag_info_array tag_table_IFD = {
584 : { 0x000B, "ACDComment"},
585 : { 0x00FE, "NewSubFile"}, /* better name it 'ImageType' ? */
586 : { 0x00FF, "SubFile"},
587 : { 0x0100, "ImageWidth"},
588 : { 0x0101, "ImageLength"},
589 : { 0x0102, "BitsPerSample"},
590 : { 0x0103, "Compression"},
591 : { 0x0106, "PhotometricInterpretation"},
592 : { 0x010A, "FillOrder"},
593 : { 0x010D, "DocumentName"},
594 : { 0x010E, "ImageDescription"},
595 : { 0x010F, "Make"},
596 : { 0x0110, "Model"},
597 : { 0x0111, "StripOffsets"},
598 : { 0x0112, "Orientation"},
599 : { 0x0115, "SamplesPerPixel"},
600 : { 0x0116, "RowsPerStrip"},
601 : { 0x0117, "StripByteCounts"},
602 : { 0x0118, "MinSampleValue"},
603 : { 0x0119, "MaxSampleValue"},
604 : { 0x011A, "XResolution"},
605 : { 0x011B, "YResolution"},
606 : { 0x011C, "PlanarConfiguration"},
607 : { 0x011D, "PageName"},
608 : { 0x011E, "XPosition"},
609 : { 0x011F, "YPosition"},
610 : { 0x0120, "FreeOffsets"},
611 : { 0x0121, "FreeByteCounts"},
612 : { 0x0122, "GrayResponseUnit"},
613 : { 0x0123, "GrayResponseCurve"},
614 : { 0x0124, "T4Options"},
615 : { 0x0125, "T6Options"},
616 : { 0x0128, "ResolutionUnit"},
617 : { 0x0129, "PageNumber"},
618 : { 0x012D, "TransferFunction"},
619 : { 0x0131, "Software"},
620 : { 0x0132, "DateTime"},
621 : { 0x013B, "Artist"},
622 : { 0x013C, "HostComputer"},
623 : { 0x013D, "Predictor"},
624 : { 0x013E, "WhitePoint"},
625 : { 0x013F, "PrimaryChromaticities"},
626 : { 0x0140, "ColorMap"},
627 : { 0x0141, "HalfToneHints"},
628 : { 0x0142, "TileWidth"},
629 : { 0x0143, "TileLength"},
630 : { 0x0144, "TileOffsets"},
631 : { 0x0145, "TileByteCounts"},
632 : { 0x014A, "SubIFD"},
633 : { 0x014C, "InkSet"},
634 : { 0x014D, "InkNames"},
635 : { 0x014E, "NumberOfInks"},
636 : { 0x0150, "DotRange"},
637 : { 0x0151, "TargetPrinter"},
638 : { 0x0152, "ExtraSample"},
639 : { 0x0153, "SampleFormat"},
640 : { 0x0154, "SMinSampleValue"},
641 : { 0x0155, "SMaxSampleValue"},
642 : { 0x0156, "TransferRange"},
643 : { 0x0157, "ClipPath"},
644 : { 0x0158, "XClipPathUnits"},
645 : { 0x0159, "YClipPathUnits"},
646 : { 0x015A, "Indexed"},
647 : { 0x015B, "JPEGTables"},
648 : { 0x015F, "OPIProxy"},
649 : { 0x0200, "JPEGProc"},
650 : { 0x0201, "JPEGInterchangeFormat"},
651 : { 0x0202, "JPEGInterchangeFormatLength"},
652 : { 0x0203, "JPEGRestartInterval"},
653 : { 0x0205, "JPEGLosslessPredictors"},
654 : { 0x0206, "JPEGPointTransforms"},
655 : { 0x0207, "JPEGQTables"},
656 : { 0x0208, "JPEGDCTables"},
657 : { 0x0209, "JPEGACTables"},
658 : { 0x0211, "YCbCrCoefficients"},
659 : { 0x0212, "YCbCrSubSampling"},
660 : { 0x0213, "YCbCrPositioning"},
661 : { 0x0214, "ReferenceBlackWhite"},
662 : { 0x02BC, "ExtensibleMetadataPlatform"}, /* XAP: Extensible Authoring Publishing, obsoleted by XMP: Extensible Metadata Platform */
663 : { 0x0301, "Gamma"},
664 : { 0x0302, "ICCProfileDescriptor"},
665 : { 0x0303, "SRGBRenderingIntent"},
666 : { 0x0320, "ImageTitle"},
667 : { 0x5001, "ResolutionXUnit"},
668 : { 0x5002, "ResolutionYUnit"},
669 : { 0x5003, "ResolutionXLengthUnit"},
670 : { 0x5004, "ResolutionYLengthUnit"},
671 : { 0x5005, "PrintFlags"},
672 : { 0x5006, "PrintFlagsVersion"},
673 : { 0x5007, "PrintFlagsCrop"},
674 : { 0x5008, "PrintFlagsBleedWidth"},
675 : { 0x5009, "PrintFlagsBleedWidthScale"},
676 : { 0x500A, "HalftoneLPI"},
677 : { 0x500B, "HalftoneLPIUnit"},
678 : { 0x500C, "HalftoneDegree"},
679 : { 0x500D, "HalftoneShape"},
680 : { 0x500E, "HalftoneMisc"},
681 : { 0x500F, "HalftoneScreen"},
682 : { 0x5010, "JPEGQuality"},
683 : { 0x5011, "GridSize"},
684 : { 0x5012, "ThumbnailFormat"},
685 : { 0x5013, "ThumbnailWidth"},
686 : { 0x5014, "ThumbnailHeight"},
687 : { 0x5015, "ThumbnailColorDepth"},
688 : { 0x5016, "ThumbnailPlanes"},
689 : { 0x5017, "ThumbnailRawBytes"},
690 : { 0x5018, "ThumbnailSize"},
691 : { 0x5019, "ThumbnailCompressedSize"},
692 : { 0x501A, "ColorTransferFunction"},
693 : { 0x501B, "ThumbnailData"},
694 : { 0x5020, "ThumbnailImageWidth"},
695 : { 0x5021, "ThumbnailImageHeight"},
696 : { 0x5022, "ThumbnailBitsPerSample"},
697 : { 0x5023, "ThumbnailCompression"},
698 : { 0x5024, "ThumbnailPhotometricInterp"},
699 : { 0x5025, "ThumbnailImageDescription"},
700 : { 0x5026, "ThumbnailEquipMake"},
701 : { 0x5027, "ThumbnailEquipModel"},
702 : { 0x5028, "ThumbnailStripOffsets"},
703 : { 0x5029, "ThumbnailOrientation"},
704 : { 0x502A, "ThumbnailSamplesPerPixel"},
705 : { 0x502B, "ThumbnailRowsPerStrip"},
706 : { 0x502C, "ThumbnailStripBytesCount"},
707 : { 0x502D, "ThumbnailResolutionX"},
708 : { 0x502E, "ThumbnailResolutionY"},
709 : { 0x502F, "ThumbnailPlanarConfig"},
710 : { 0x5030, "ThumbnailResolutionUnit"},
711 : { 0x5031, "ThumbnailTransferFunction"},
712 : { 0x5032, "ThumbnailSoftwareUsed"},
713 : { 0x5033, "ThumbnailDateTime"},
714 : { 0x5034, "ThumbnailArtist"},
715 : { 0x5035, "ThumbnailWhitePoint"},
716 : { 0x5036, "ThumbnailPrimaryChromaticities"},
717 : { 0x5037, "ThumbnailYCbCrCoefficients"},
718 : { 0x5038, "ThumbnailYCbCrSubsampling"},
719 : { 0x5039, "ThumbnailYCbCrPositioning"},
720 : { 0x503A, "ThumbnailRefBlackWhite"},
721 : { 0x503B, "ThumbnailCopyRight"},
722 : { 0x5090, "LuminanceTable"},
723 : { 0x5091, "ChrominanceTable"},
724 : { 0x5100, "FrameDelay"},
725 : { 0x5101, "LoopCount"},
726 : { 0x5110, "PixelUnit"},
727 : { 0x5111, "PixelPerUnitX"},
728 : { 0x5112, "PixelPerUnitY"},
729 : { 0x5113, "PaletteHistogram"},
730 : { 0x1000, "RelatedImageFileFormat"},
731 : { 0x800D, "ImageID"},
732 : { 0x80E3, "Matteing"}, /* obsoleted by ExtraSamples */
733 : { 0x80E4, "DataType"}, /* obsoleted by SampleFormat */
734 : { 0x80E5, "ImageDepth"},
735 : { 0x80E6, "TileDepth"},
736 : { 0x828D, "CFARepeatPatternDim"},
737 : { 0x828E, "CFAPattern"},
738 : { 0x828F, "BatteryLevel"},
739 : { 0x8298, "Copyright"},
740 : { 0x829A, "ExposureTime"},
741 : { 0x829D, "FNumber"},
742 : { 0x83BB, "IPTC/NAA"},
743 : { 0x84E3, "IT8RasterPadding"},
744 : { 0x84E5, "IT8ColorTable"},
745 : { 0x8649, "ImageResourceInformation"}, /* PhotoShop */
746 : { 0x8769, "Exif_IFD_Pointer"},
747 : { 0x8773, "ICC_Profile"},
748 : { 0x8822, "ExposureProgram"},
749 : { 0x8824, "SpectralSensity"},
750 : { 0x8828, "OECF"},
751 : { 0x8825, "GPS_IFD_Pointer"},
752 : { 0x8827, "ISOSpeedRatings"},
753 : { 0x8828, "OECF"},
754 : { 0x9000, "ExifVersion"},
755 : { 0x9003, "DateTimeOriginal"},
756 : { 0x9004, "DateTimeDigitized"},
757 : { 0x9101, "ComponentsConfiguration"},
758 : { 0x9102, "CompressedBitsPerPixel"},
759 : { 0x9201, "ShutterSpeedValue"},
760 : { 0x9202, "ApertureValue"},
761 : { 0x9203, "BrightnessValue"},
762 : { 0x9204, "ExposureBiasValue"},
763 : { 0x9205, "MaxApertureValue"},
764 : { 0x9206, "SubjectDistance"},
765 : { 0x9207, "MeteringMode"},
766 : { 0x9208, "LightSource"},
767 : { 0x9209, "Flash"},
768 : { 0x920A, "FocalLength"},
769 : { 0x920B, "FlashEnergy"}, /* 0xA20B in JPEG */
770 : { 0x920C, "SpatialFrequencyResponse"}, /* 0xA20C - - */
771 : { 0x920D, "Noise"},
772 : { 0x920E, "FocalPlaneXResolution"}, /* 0xA20E - - */
773 : { 0x920F, "FocalPlaneYResolution"}, /* 0xA20F - - */
774 : { 0x9210, "FocalPlaneResolutionUnit"}, /* 0xA210 - - */
775 : { 0x9211, "ImageNumber"},
776 : { 0x9212, "SecurityClassification"},
777 : { 0x9213, "ImageHistory"},
778 : { 0x9214, "SubjectLocation"}, /* 0xA214 - - */
779 : { 0x9215, "ExposureIndex"}, /* 0xA215 - - */
780 : { 0x9216, "TIFF/EPStandardID"},
781 : { 0x9217, "SensingMethod"}, /* 0xA217 - - */
782 : { 0x923F, "StoNits"},
783 : { 0x927C, "MakerNote"},
784 : { 0x9286, "UserComment"},
785 : { 0x9290, "SubSecTime"},
786 : { 0x9291, "SubSecTimeOriginal"},
787 : { 0x9292, "SubSecTimeDigitized"},
788 : { 0x935C, "ImageSourceData"}, /* "Adobe Photoshop Document Data Block": 8BIM... */
789 : { 0x9c9b, "Title" }, /* Win XP specific, Unicode */
790 : { 0x9c9c, "Comments" }, /* Win XP specific, Unicode */
791 : { 0x9c9d, "Author" }, /* Win XP specific, Unicode */
792 : { 0x9c9e, "Keywords" }, /* Win XP specific, Unicode */
793 : { 0x9c9f, "Subject" }, /* Win XP specific, Unicode, not to be confused with SubjectDistance and SubjectLocation */
794 : { 0xA000, "FlashPixVersion"},
795 : { 0xA001, "ColorSpace"},
796 : { 0xA002, "ExifImageWidth"},
797 : { 0xA003, "ExifImageLength"},
798 : { 0xA004, "RelatedSoundFile"},
799 : { 0xA005, "InteroperabilityOffset"},
800 : { 0xA20B, "FlashEnergy"}, /* 0x920B in TIFF/EP */
801 : { 0xA20C, "SpatialFrequencyResponse"}, /* 0x920C - - */
802 : { 0xA20D, "Noise"},
803 : { 0xA20E, "FocalPlaneXResolution"}, /* 0x920E - - */
804 : { 0xA20F, "FocalPlaneYResolution"}, /* 0x920F - - */
805 : { 0xA210, "FocalPlaneResolutionUnit"}, /* 0x9210 - - */
806 : { 0xA211, "ImageNumber"},
807 : { 0xA212, "SecurityClassification"},
808 : { 0xA213, "ImageHistory"},
809 : { 0xA214, "SubjectLocation"}, /* 0x9214 - - */
810 : { 0xA215, "ExposureIndex"}, /* 0x9215 - - */
811 : { 0xA216, "TIFF/EPStandardID"},
812 : { 0xA217, "SensingMethod"}, /* 0x9217 - - */
813 : { 0xA300, "FileSource"},
814 : { 0xA301, "SceneType"},
815 : { 0xA302, "CFAPattern"},
816 : { 0xA401, "CustomRendered"},
817 : { 0xA402, "ExposureMode"},
818 : { 0xA403, "WhiteBalance"},
819 : { 0xA404, "DigitalZoomRatio"},
820 : { 0xA405, "FocalLengthIn35mmFilm"},
821 : { 0xA406, "SceneCaptureType"},
822 : { 0xA407, "GainControl"},
823 : { 0xA408, "Contrast"},
824 : { 0xA409, "Saturation"},
825 : { 0xA40A, "Sharpness"},
826 : { 0xA40B, "DeviceSettingDescription"},
827 : { 0xA40C, "SubjectDistanceRange"},
828 : { 0xA420, "ImageUniqueID"},
829 : TAG_TABLE_END
830 : } ;
831 :
832 : static tag_info_array tag_table_GPS = {
833 : { 0x0000, "GPSVersion"},
834 : { 0x0001, "GPSLatitudeRef"},
835 : { 0x0002, "GPSLatitude"},
836 : { 0x0003, "GPSLongitudeRef"},
837 : { 0x0004, "GPSLongitude"},
838 : { 0x0005, "GPSAltitudeRef"},
839 : { 0x0006, "GPSAltitude"},
840 : { 0x0007, "GPSTimeStamp"},
841 : { 0x0008, "GPSSatellites"},
842 : { 0x0009, "GPSStatus"},
843 : { 0x000A, "GPSMeasureMode"},
844 : { 0x000B, "GPSDOP"},
845 : { 0x000C, "GPSSpeedRef"},
846 : { 0x000D, "GPSSpeed"},
847 : { 0x000E, "GPSTrackRef"},
848 : { 0x000F, "GPSTrack"},
849 : { 0x0010, "GPSImgDirectionRef"},
850 : { 0x0011, "GPSImgDirection"},
851 : { 0x0012, "GPSMapDatum"},
852 : { 0x0013, "GPSDestLatitudeRef"},
853 : { 0x0014, "GPSDestLatitude"},
854 : { 0x0015, "GPSDestLongitudeRef"},
855 : { 0x0016, "GPSDestLongitude"},
856 : { 0x0017, "GPSDestBearingRef"},
857 : { 0x0018, "GPSDestBearing"},
858 : { 0x0019, "GPSDestDistanceRef"},
859 : { 0x001A, "GPSDestDistance"},
860 : { 0x001B, "GPSProcessingMode"},
861 : { 0x001C, "GPSAreaInformation"},
862 : { 0x001D, "GPSDateStamp"},
863 : { 0x001E, "GPSDifferential"},
864 : TAG_TABLE_END
865 : };
866 :
867 : static tag_info_array tag_table_IOP = {
868 : { 0x0001, "InterOperabilityIndex"}, /* should be 'R98' or 'THM' */
869 : { 0x0002, "InterOperabilityVersion"},
870 : { 0x1000, "RelatedFileFormat"},
871 : { 0x1001, "RelatedImageWidth"},
872 : { 0x1002, "RelatedImageHeight"},
873 : TAG_TABLE_END
874 : };
875 :
876 : static tag_info_array tag_table_VND_CANON = {
877 : { 0x0001, "ModeArray"}, /* guess */
878 : { 0x0004, "ImageInfo"}, /* guess */
879 : { 0x0006, "ImageType"},
880 : { 0x0007, "FirmwareVersion"},
881 : { 0x0008, "ImageNumber"},
882 : { 0x0009, "OwnerName"},
883 : { 0x000C, "Camera"},
884 : { 0x000F, "CustomFunctions"},
885 : TAG_TABLE_END
886 : };
887 :
888 : static tag_info_array tag_table_VND_CASIO = {
889 : { 0x0001, "RecordingMode"},
890 : { 0x0002, "Quality"},
891 : { 0x0003, "FocusingMode"},
892 : { 0x0004, "FlashMode"},
893 : { 0x0005, "FlashIntensity"},
894 : { 0x0006, "ObjectDistance"},
895 : { 0x0007, "WhiteBalance"},
896 : { 0x000A, "DigitalZoom"},
897 : { 0x000B, "Sharpness"},
898 : { 0x000C, "Contrast"},
899 : { 0x000D, "Saturation"},
900 : { 0x0014, "CCDSensitivity"},
901 : TAG_TABLE_END
902 : };
903 :
904 : static tag_info_array tag_table_VND_FUJI = {
905 : { 0x0000, "Version"},
906 : { 0x1000, "Quality"},
907 : { 0x1001, "Sharpness"},
908 : { 0x1002, "WhiteBalance"},
909 : { 0x1003, "Color"},
910 : { 0x1004, "Tone"},
911 : { 0x1010, "FlashMode"},
912 : { 0x1011, "FlashStrength"},
913 : { 0x1020, "Macro"},
914 : { 0x1021, "FocusMode"},
915 : { 0x1030, "SlowSync"},
916 : { 0x1031, "PictureMode"},
917 : { 0x1100, "ContTake"},
918 : { 0x1300, "BlurWarning"},
919 : { 0x1301, "FocusWarning"},
920 : { 0x1302, "AEWarning "},
921 : TAG_TABLE_END
922 : };
923 :
924 : static tag_info_array tag_table_VND_NIKON = {
925 : { 0x0003, "Quality"},
926 : { 0x0004, "ColorMode"},
927 : { 0x0005, "ImageAdjustment"},
928 : { 0x0006, "CCDSensitivity"},
929 : { 0x0007, "WhiteBalance"},
930 : { 0x0008, "Focus"},
931 : { 0x000a, "DigitalZoom"},
932 : { 0x000b, "Converter"},
933 : TAG_TABLE_END
934 : };
935 :
936 : static tag_info_array tag_table_VND_NIKON_990 = {
937 : { 0x0001, "Version"},
938 : { 0x0002, "ISOSetting"},
939 : { 0x0003, "ColorMode"},
940 : { 0x0004, "Quality"},
941 : { 0x0005, "WhiteBalance"},
942 : { 0x0006, "ImageSharpening"},
943 : { 0x0007, "FocusMode"},
944 : { 0x0008, "FlashSetting"},
945 : { 0x000F, "ISOSelection"},
946 : { 0x0080, "ImageAdjustment"},
947 : { 0x0082, "AuxiliaryLens"},
948 : { 0x0085, "ManualFocusDistance"},
949 : { 0x0086, "DigitalZoom"},
950 : { 0x0088, "AFFocusPosition"},
951 : { 0x0010, "DataDump"},
952 : TAG_TABLE_END
953 : };
954 :
955 : static tag_info_array tag_table_VND_OLYMPUS = {
956 : { 0x0200, "SpecialMode"},
957 : { 0x0201, "JPEGQuality"},
958 : { 0x0202, "Macro"},
959 : { 0x0204, "DigitalZoom"},
960 : { 0x0207, "SoftwareRelease"},
961 : { 0x0208, "PictureInfo"},
962 : { 0x0209, "CameraId"},
963 : { 0x0F00, "DataDump"},
964 : TAG_TABLE_END
965 : };
966 :
967 : typedef enum mn_byte_order_t {
968 : MN_ORDER_INTEL = 0,
969 : MN_ORDER_MOTOROLA = 1,
970 : MN_ORDER_NORMAL
971 : } mn_byte_order_t;
972 :
973 : typedef enum mn_offset_mode_t {
974 : MN_OFFSET_NORMAL,
975 : MN_OFFSET_MAKER,
976 : MN_OFFSET_GUESS
977 : } mn_offset_mode_t;
978 :
979 : typedef struct {
980 : tag_table_type tag_table;
981 : char * make;
982 : char * model;
983 : char * id_string;
984 : int id_string_len;
985 : int offset;
986 : mn_byte_order_t byte_order;
987 : mn_offset_mode_t offset_mode;
988 : } maker_note_type;
989 :
990 : static const maker_note_type maker_note_array[] = {
991 : { tag_table_VND_CANON, "Canon", NULL, NULL, 0, 0, MN_ORDER_INTEL, MN_OFFSET_GUESS},
992 : /* { tag_table_VND_CANON, "Canon", NULL, NULL, 0, 0, MN_ORDER_NORMAL, MN_OFFSET_NORMAL},*/
993 : { tag_table_VND_CASIO, "CASIO", NULL, NULL, 0, 0, MN_ORDER_MOTOROLA, MN_OFFSET_NORMAL},
994 : { tag_table_VND_FUJI, "FUJIFILM", NULL, "FUJIFILM\x0C\x00\x00\x00", 12, 12, MN_ORDER_INTEL, MN_OFFSET_MAKER},
995 : { tag_table_VND_NIKON, "NIKON", NULL, "Nikon\x00\x01\x00", 8, 8, MN_ORDER_NORMAL, MN_OFFSET_NORMAL},
996 : { tag_table_VND_NIKON_990, "NIKON", NULL, NULL, 0, 0, MN_ORDER_NORMAL, MN_OFFSET_NORMAL},
997 : { tag_table_VND_OLYMPUS, "OLYMPUS OPTICAL CO.,LTD", NULL, "OLYMP\x00\x01\x00", 8, 8, MN_ORDER_NORMAL, MN_OFFSET_NORMAL},
998 : };
999 : /* }}} */
1000 :
1001 : /* {{{ exif_get_tagname
1002 : Get headername for tag_num or NULL if not defined */
1003 : static char * exif_get_tagname(int tag_num, char *ret, int len, tag_table_type tag_table TSRMLS_DC)
1004 481 : {
1005 : int i, t;
1006 : char tmp[32];
1007 :
1008 34871 : for (i = 0; (t = tag_table[i].Tag) != TAG_END_OF_LIST; i++) {
1009 34845 : if (t == tag_num) {
1010 455 : if (ret && len) {
1011 447 : strlcpy(ret, tag_table[i].Desc, abs(len));
1012 447 : if (len < 0) {
1013 0 : memset(ret + strlen(ret), ' ', -len - strlen(ret) - 1);
1014 0 : ret[-len - 1] = '\0';
1015 : }
1016 447 : return ret;
1017 : }
1018 8 : return tag_table[i].Desc;
1019 : }
1020 : }
1021 :
1022 26 : if (ret && len) {
1023 0 : snprintf(tmp, sizeof(tmp), "UndefinedTag:0x%04X", tag_num);
1024 0 : strlcpy(ret, tmp, abs(len));
1025 0 : if (len < 0) {
1026 0 : memset(ret + strlen(ret), ' ', -len - strlen(ret) - 1);
1027 0 : ret[-len - 1] = '\0';
1028 : }
1029 0 : return ret;
1030 : }
1031 26 : return "";
1032 : }
1033 : /* }}} */
1034 :
1035 : /* {{{ exif_char_dump
1036 : * Do not use! This is a debug function... */
1037 : #ifdef EXIF_DEBUG
1038 : static unsigned char* exif_char_dump(unsigned char * addr, int len, int offset)
1039 : {
1040 : static unsigned char buf[4096+1];
1041 : static unsigned char tmp[20];
1042 : int c, i, p=0, n = 5+31;
1043 :
1044 : p += slprintf(buf+p, sizeof(buf)-p, "\nDump Len: %08X (%d)", len, len);
1045 : if (len) {
1046 : for(i=0; i<len+15 && p+n<=sizeof(buf); i++) {
1047 : if (i%16==0) {
1048 : p += slprintf(buf+p, sizeof(buf)-p, "\n%08X: ", i+offset);
1049 : }
1050 : if (i<len) {
1051 : c = *addr++;
1052 : p += slprintf(buf+p, sizeof(buf)-p, "%02X ", c);
1053 : tmp[i%16] = c>=32 ? c : '.';
1054 : tmp[(i%16)+1] = '\0';
1055 : } else {
1056 : p += slprintf(buf+p, sizeof(buf)-p, " ");
1057 : }
1058 : if (i%16==15) {
1059 : p += slprintf(buf+p, sizeof(buf)-p, " %s", tmp);
1060 : if (i>=len) {
1061 : break;
1062 : }
1063 : }
1064 : }
1065 : }
1066 : buf[sizeof(buf)-1] = '\0';
1067 : return buf;
1068 : }
1069 : #endif
1070 : /* }}} */
1071 :
1072 : /* {{{ php_jpg_get16
1073 : Get 16 bits motorola order (always) for jpeg header stuff.
1074 : */
1075 : static int php_jpg_get16(void *value)
1076 40 : {
1077 40 : return (((uchar *)value)[0] << 8) | ((uchar *)value)[1];
1078 : }
1079 : /* }}} */
1080 :
1081 : /* {{{ php_ifd_get16u
1082 : * Convert a 16 bit unsigned value from file's native byte order */
1083 : static int php_ifd_get16u(void *value, int motorola_intel)
1084 9149 : {
1085 9149 : if (motorola_intel) {
1086 4110 : return (((uchar *)value)[0] << 8) | ((uchar *)value)[1];
1087 : } else {
1088 5039 : return (((uchar *)value)[1] << 8) | ((uchar *)value)[0];
1089 : }
1090 : }
1091 : /* }}} */
1092 :
1093 : /* {{{ php_ifd_get16s
1094 : * Convert a 16 bit signed value from file's native byte order */
1095 : static signed short php_ifd_get16s(void *value, int motorola_intel)
1096 0 : {
1097 0 : return (signed short)php_ifd_get16u(value, motorola_intel);
1098 : }
1099 : /* }}} */
1100 :
1101 : /* {{{ php_ifd_get32s
1102 : * Convert a 32 bit signed value from file's native byte order */
1103 : static int php_ifd_get32s(void *value, int motorola_intel)
1104 1517 : {
1105 1517 : if (motorola_intel) {
1106 736 : return (((char *)value)[0] << 24)
1107 : | (((uchar *)value)[1] << 16)
1108 : | (((uchar *)value)[2] << 8 )
1109 : | (((uchar *)value)[3] );
1110 : } else {
1111 781 : return (((char *)value)[3] << 24)
1112 : | (((uchar *)value)[2] << 16)
1113 : | (((uchar *)value)[1] << 8 )
1114 : | (((uchar *)value)[0] );
1115 : }
1116 : }
1117 : /* }}} */
1118 :
1119 : /* {{{ php_ifd_get32u
1120 : * Write 32 bit unsigned value to data */
1121 : static unsigned php_ifd_get32u(void *value, int motorola_intel)
1122 1517 : {
1123 1517 : return (unsigned)php_ifd_get32s(value, motorola_intel) & 0xffffffff;
1124 : }
1125 : /* }}} */
1126 :
1127 : /* {{{ php_ifd_set16u
1128 : * Write 16 bit unsigned value to data */
1129 : static void php_ifd_set16u(char *data, unsigned int value, int motorola_intel)
1130 0 : {
1131 0 : if (motorola_intel) {
1132 0 : data[0] = (value & 0xFF00) >> 8;
1133 0 : data[1] = (value & 0x00FF);
1134 : } else {
1135 0 : data[1] = (value & 0xFF00) >> 8;
1136 0 : data[0] = (value & 0x00FF);
1137 : }
1138 0 : }
1139 : /* }}} */
1140 :
1141 : /* {{{ php_ifd_set32u
1142 : * Convert a 32 bit unsigned value from file's native byte order */
1143 : static void php_ifd_set32u(char *data, size_t value, int motorola_intel)
1144 0 : {
1145 0 : if (motorola_intel) {
1146 0 : data[0] = (value & 0xFF000000) >> 24;
1147 0 : data[1] = (value & 0x00FF0000) >> 16;
1148 0 : data[2] = (value & 0x0000FF00) >> 8;
1149 0 : data[3] = (value & 0x000000FF);
1150 : } else {
1151 0 : data[3] = (value & 0xFF000000) >> 24;
1152 0 : data[2] = (value & 0x00FF0000) >> 16;
1153 0 : data[1] = (value & 0x0000FF00) >> 8;
1154 0 : data[0] = (value & 0x000000FF);
1155 : }
1156 0 : }
1157 : /* }}} */
1158 :
1159 : #ifdef EXIF_DEBUG
1160 : char * exif_dump_data(int *dump_free, int format, int components, int length, int motorola_intel, char *value_ptr TSRMLS_DC) /* {{{ */
1161 : {
1162 : char *dump;
1163 : int len;
1164 :
1165 : *dump_free = 0;
1166 : if (format == TAG_FMT_STRING) {
1167 : return value_ptr ? value_ptr : "<no data>";
1168 : }
1169 : if (format == TAG_FMT_UNDEFINED) {
1170 : return "<undefined>\n";
1171 : }
1172 : if (format == TAG_FMT_IFD) {
1173 : return "";
1174 : }
1175 : if (format == TAG_FMT_SINGLE || format == TAG_FMT_DOUBLE) {
1176 : return "<not implemented>";
1177 : }
1178 : *dump_free = 1;
1179 : if (components > 1) {
1180 : len = spprintf(&dump, 0, "(%d,%d) {", components, length);
1181 : } else {
1182 : len = spprintf(&dump, 0, "{");
1183 : }
1184 : while(components > 0) {
1185 : switch(format) {
1186 : case TAG_FMT_BYTE:
1187 : case TAG_FMT_UNDEFINED:
1188 : case TAG_FMT_STRING:
1189 : case TAG_FMT_SBYTE:
1190 : dump = erealloc(dump, len + 4 + 1);
1191 : snprintf(dump + len, 4 + 1, "0x%02X", *value_ptr);
1192 : len += 4;
1193 : value_ptr++;
1194 : break;
1195 : case TAG_FMT_USHORT:
1196 : case TAG_FMT_SSHORT:
1197 : dump = erealloc(dump, len + 6 + 1);
1198 : snprintf(dump + len, 6 + 1, "0x%04X", php_ifd_get16s(value_ptr, motorola_intel));
1199 : len += 6;
1200 : value_ptr += 2;
1201 : break;
1202 : case TAG_FMT_ULONG:
1203 : case TAG_FMT_SLONG:
1204 : dump = erealloc(dump, len + 6 + 1);
1205 : snprintf(dump + len, 6 + 1, "0x%04X", php_ifd_get32s(value_ptr, motorola_intel));
1206 : len += 6;
1207 : value_ptr += 4;
1208 : break;
1209 : case TAG_FMT_URATIONAL:
1210 : case TAG_FMT_SRATIONAL:
1211 : dump = erealloc(dump, len + 13 + 1);
1212 : snprintf(dump + len, 13 + 1, "0x%04X/0x%04X", php_ifd_get32s(value_ptr, motorola_intel), php_ifd_get32s(value_ptr+4, motorola_intel));
1213 : len += 13;
1214 : value_ptr += 8;
1215 : break;
1216 : }
1217 : if (components > 0) {
1218 : dump = erealloc(dump, len + 2 + 1);
1219 : snprintf(dump + len, 2 + 1, ", ");
1220 : len += 2;
1221 : components--;
1222 : } else{
1223 : break;
1224 : }
1225 : }
1226 : dump = erealloc(dump, len + 1 + 1);
1227 : snprintf(dump + len, 1 + 1, "}");
1228 : return dump;
1229 : }
1230 : /* }}} */
1231 : #endif
1232 :
1233 : /* {{{ exif_convert_any_format
1234 : * Evaluate number, be it int, rational, or float from directory. */
1235 : static double exif_convert_any_format(void *value, int format, int motorola_intel TSRMLS_DC)
1236 7 : {
1237 : int s_den;
1238 : unsigned u_den;
1239 :
1240 7 : switch(format) {
1241 0 : case TAG_FMT_SBYTE: return *(signed char *)value;
1242 0 : case TAG_FMT_BYTE: return *(uchar *)value;
1243 :
1244 0 : case TAG_FMT_USHORT: return php_ifd_get16u(value, motorola_intel);
1245 0 : case TAG_FMT_ULONG: return php_ifd_get32u(value, motorola_intel);
1246 :
1247 : case TAG_FMT_URATIONAL:
1248 7 : u_den = php_ifd_get32u(4+(char *)value, motorola_intel);
1249 7 : if (u_den == 0) {
1250 0 : return 0;
1251 : } else {
1252 7 : return (double)php_ifd_get32u(value, motorola_intel) / u_den;
1253 : }
1254 :
1255 : case TAG_FMT_SRATIONAL:
1256 0 : s_den = php_ifd_get32s(4+(char *)value, motorola_intel);
1257 0 : if (s_den == 0) {
1258 0 : return 0;
1259 : } else {
1260 0 : return (double)php_ifd_get32s(value, motorola_intel) / s_den;
1261 : }
1262 :
1263 0 : case TAG_FMT_SSHORT: return (signed short)php_ifd_get16u(value, motorola_intel);
1264 0 : case TAG_FMT_SLONG: return php_ifd_get32s(value, motorola_intel);
1265 :
1266 : /* Not sure if this is correct (never seen float used in Exif format) */
1267 : case TAG_FMT_SINGLE:
1268 : #ifdef EXIF_DEBUG
1269 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found value of type single");
1270 : #endif
1271 0 : return (double)*(float *)value;
1272 : case TAG_FMT_DOUBLE:
1273 : #ifdef EXIF_DEBUG
1274 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found value of type double");
1275 : #endif
1276 0 : return *(double *)value;
1277 : }
1278 0 : return 0;
1279 : }
1280 : /* }}} */
1281 :
1282 : /* {{{ exif_convert_any_to_int
1283 : * Evaluate number, be it int, rational, or float from directory. */
1284 : static size_t exif_convert_any_to_int(void *value, int format, int motorola_intel TSRMLS_DC)
1285 19 : {
1286 : int s_den;
1287 : unsigned u_den;
1288 :
1289 19 : switch(format) {
1290 0 : case TAG_FMT_SBYTE: return *(signed char *)value;
1291 0 : case TAG_FMT_BYTE: return *(uchar *)value;
1292 :
1293 7 : case TAG_FMT_USHORT: return php_ifd_get16u(value, motorola_intel);
1294 12 : case TAG_FMT_ULONG: return php_ifd_get32u(value, motorola_intel);
1295 :
1296 : case TAG_FMT_URATIONAL:
1297 0 : u_den = php_ifd_get32u(4+(char *)value, motorola_intel);
1298 0 : if (u_den == 0) {
1299 0 : return 0;
1300 : } else {
1301 0 : return php_ifd_get32u(value, motorola_intel) / u_den;
1302 : }
1303 :
1304 : case TAG_FMT_SRATIONAL:
1305 0 : s_den = php_ifd_get32s(4+(char *)value, motorola_intel);
1306 0 : if (s_den == 0) {
1307 0 : return 0;
1308 : } else {
1309 0 : return php_ifd_get32s(value, motorola_intel) / s_den;
1310 : }
1311 :
1312 0 : case TAG_FMT_SSHORT: return php_ifd_get16u(value, motorola_intel);
1313 0 : case TAG_FMT_SLONG: return php_ifd_get32s(value, motorola_intel);
1314 :
1315 : /* Not sure if this is correct (never seen float used in Exif format) */
1316 : case TAG_FMT_SINGLE:
1317 : #ifdef EXIF_DEBUG
1318 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found value of type single");
1319 : #endif
1320 0 : return (size_t)*(float *)value;
1321 : case TAG_FMT_DOUBLE:
1322 : #ifdef EXIF_DEBUG
1323 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Found value of type double");
1324 : #endif
1325 0 : return (size_t)*(double *)value;
1326 : }
1327 0 : return 0;
1328 : }
1329 : /* }}} */
1330 :
1331 : /* {{{ struct image_info_value, image_info_list
1332 : */
1333 : #ifndef WORD
1334 : #define WORD unsigned short
1335 : #endif
1336 : #ifndef DWORD
1337 : #define DWORD unsigned int
1338 : #endif
1339 :
1340 : typedef struct {
1341 : int num;
1342 : int den;
1343 : } signed_rational;
1344 :
1345 : typedef struct {
1346 : unsigned int num;
1347 : unsigned int den;
1348 : } unsigned_rational;
1349 :
1350 : typedef union _image_info_value {
1351 : char *s;
1352 : unsigned u;
1353 : int i;
1354 : float f;
1355 : double d;
1356 : signed_rational sr;
1357 : unsigned_rational ur;
1358 : union _image_info_value *list;
1359 : } image_info_value;
1360 :
1361 : typedef struct {
1362 : WORD tag;
1363 : WORD format;
1364 : DWORD length;
1365 : DWORD dummy; /* value ptr of tiff directory entry */
1366 : char *name;
1367 : image_info_value value;
1368 : } image_info_data;
1369 :
1370 : typedef struct {
1371 : int count;
1372 : image_info_data *list;
1373 : } image_info_list;
1374 : /* }}} */
1375 :
1376 : /* {{{ exif_get_sectionname
1377 : Returns the name of a section
1378 : */
1379 : #define SECTION_FILE 0
1380 : #define SECTION_COMPUTED 1
1381 : #define SECTION_ANY_TAG 2
1382 : #define SECTION_IFD0 3
1383 : #define SECTION_THUMBNAIL 4
1384 : #define SECTION_COMMENT 5
1385 : #define SECTION_APP0 6
1386 : #define SECTION_EXIF 7
1387 : #define SECTION_FPIX 8
1388 : #define SECTION_GPS 9
1389 : #define SECTION_INTEROP 10
1390 : #define SECTION_APP12 11
1391 : #define SECTION_WINXP 12
1392 : #define SECTION_MAKERNOTE 13
1393 : #define SECTION_COUNT 14
1394 :
1395 : #define FOUND_FILE (1<<SECTION_FILE)
1396 : #define FOUND_COMPUTED (1<<SECTION_COMPUTED)
1397 : #define FOUND_ANY_TAG (1<<SECTION_ANY_TAG)
1398 : #define FOUND_IFD0 (1<<SECTION_IFD0)
1399 : #define FOUND_THUMBNAIL (1<<SECTION_THUMBNAIL)
1400 : #define FOUND_COMMENT (1<<SECTION_COMMENT)
1401 : #define FOUND_APP0 (1<<SECTION_APP0)
1402 : #define FOUND_EXIF (1<<SECTION_EXIF)
1403 : #define FOUND_FPIX (1<<SECTION_FPIX)
1404 : #define FOUND_GPS (1<<SECTION_GPS)
1405 : #define FOUND_INTEROP (1<<SECTION_INTEROP)
1406 : #define FOUND_APP12 (1<<SECTION_APP12)
1407 : #define FOUND_WINXP (1<<SECTION_WINXP)
1408 : #define FOUND_MAKERNOTE (1<<SECTION_MAKERNOTE)
1409 :
1410 : static char *exif_get_sectionname(int section)
1411 675 : {
1412 675 : switch(section) {
1413 45 : case SECTION_FILE: return "FILE";
1414 91 : case SECTION_COMPUTED: return "COMPUTED";
1415 61 : case SECTION_ANY_TAG: return "ANY_TAG";
1416 72 : case SECTION_IFD0: return "IFD0";
1417 50 : case SECTION_THUMBNAIL: return "THUMBNAIL";
1418 50 : case SECTION_COMMENT: return "COMMENT";
1419 35 : case SECTION_APP0: return "APP0";
1420 46 : case SECTION_EXIF: return "EXIF";
1421 35 : case SECTION_FPIX: return "FPIX";
1422 43 : case SECTION_GPS: return "GPS";
1423 39 : case SECTION_INTEROP: return "INTEROP";
1424 35 : case SECTION_APP12: return "APP12";
1425 38 : case SECTION_WINXP: return "WINXP";
1426 35 : case SECTION_MAKERNOTE: return "MAKERNOTE";
1427 : }
1428 0 : return "";
1429 : }
1430 :
1431 : static tag_table_type exif_get_tag_table(int section)
1432 226 : {
1433 226 : switch(section) {
1434 0 : case SECTION_FILE: return &tag_table_IFD[0];
1435 0 : case SECTION_COMPUTED: return &tag_table_IFD[0];
1436 0 : case SECTION_ANY_TAG: return &tag_table_IFD[0];
1437 110 : case SECTION_IFD0: return &tag_table_IFD[0];
1438 12 : case SECTION_THUMBNAIL: return &tag_table_IFD[0];
1439 0 : case SECTION_COMMENT: return &tag_table_IFD[0];
1440 0 : case SECTION_APP0: return &tag_table_IFD[0];
1441 51 : case SECTION_EXIF: return &tag_table_IFD[0];
1442 0 : case SECTION_FPIX: return &tag_table_IFD[0];
1443 36 : case SECTION_GPS: return &tag_table_GPS[0];
1444 12 : case SECTION_INTEROP: return &tag_table_IOP[0];
1445 0 : case SECTION_APP12: return &tag_table_IFD[0];
1446 5 : case SECTION_WINXP: return &tag_table_IFD[0];
1447 : }
1448 0 : return &tag_table_IFD[0];
1449 : }
1450 : /* }}} */
1451 :
1452 : /* {{{ exif_get_sectionlist
1453 : Return list of sectionnames specified by sectionlist. Return value must be freed
1454 : */
1455 : static char *exif_get_sectionlist(int sectionlist TSRMLS_DC)
1456 29 : {
1457 29 : int i, len, ml = 0;
1458 : char *sections;
1459 :
1460 435 : for(i=0; i<SECTION_COUNT; i++) {
1461 406 : ml += strlen(exif_get_sectionname(i))+2;
1462 : }
1463 29 : sections = safe_emalloc(ml, 1, 1);
1464 29 : sections[0] = '\0';
1465 29 : len = 0;
1466 435 : for(i=0; i<SECTION_COUNT; i++) {
1467 406 : if (sectionlist&(1<<i)) {
1468 87 : snprintf(sections+len, ml-len, "%s, ", exif_get_sectionname(i));
1469 87 : len = strlen(sections);
1470 : }
1471 : }
1472 29 : if (len>2)
1473 27 : sections[len-2] = '\0';
1474 29 : return sections;
1475 : }
1476 : /* }}} */
1477 :
1478 : /* {{{ struct image_info_type
1479 : This structure stores Exif header image elements in a simple manner
1480 : Used to store camera data as extracted from the various ways that it can be
1481 : stored in a nexif header
1482 : */
1483 :
1484 : typedef struct {
1485 : int type;
1486 : size_t size;
1487 : uchar *data;
1488 : } file_section;
1489 :
1490 : typedef struct {
1491 : int count;
1492 : file_section *list;
1493 : } file_section_list;
1494 :
1495 : typedef struct {
1496 : image_filetype filetype;
1497 : size_t width, height;
1498 : size_t size;
1499 : size_t offset;
1500 : char *data;
1501 : } thumbnail_data;
1502 :
1503 : typedef struct {
1504 : char *value;
1505 : size_t size;
1506 : int tag;
1507 : } xp_field_type;
1508 :
1509 : typedef struct {
1510 : int count;
1511 : xp_field_type *list;
1512 : } xp_field_list;
1513 :
1514 : /* This structure is used to store a section of a Jpeg file. */
1515 : typedef struct {
1516 : php_stream *infile;
1517 : char *FileName;
1518 : time_t FileDateTime;
1519 : size_t FileSize;
1520 : image_filetype FileType;
1521 : int Height, Width;
1522 : int IsColor;
1523 :
1524 : char *make;
1525 : char *model;
1526 :
1527 : float ApertureFNumber;
1528 : float ExposureTime;
1529 : double FocalplaneUnits;
1530 : float CCDWidth;
1531 : double FocalplaneXRes;
1532 : size_t ExifImageWidth;
1533 : float FocalLength;
1534 : float Distance;
1535 :
1536 : int motorola_intel; /* 1 Motorola; 0 Intel */
1537 :
1538 : char *UserComment;
1539 : int UserCommentLength;
1540 : char *UserCommentEncoding;
1541 : char *encode_unicode;
1542 : char *decode_unicode_be;
1543 : char *decode_unicode_le;
1544 : char *encode_jis;
1545 : char *decode_jis_be;
1546 : char *decode_jis_le;
1547 : char *Copyright;/* EXIF standard defines Copyright as "<Photographer> [ '\0' <Editor> ] ['\0']" */
1548 : char *CopyrightPhotographer;
1549 : char *CopyrightEditor;
1550 :
1551 : xp_field_list xp_fields;
1552 :
1553 : thumbnail_data Thumbnail;
1554 : /* other */
1555 : int sections_found; /* FOUND_<marker> */
1556 : image_info_list info_list[SECTION_COUNT];
1557 : /* for parsing */
1558 : int read_thumbnail;
1559 : int read_all;
1560 : int ifd_nesting_level;
1561 : /* internal */
1562 : file_section_list file;
1563 : } image_info_type;
1564 : /* }}} */
1565 :
1566 : /* {{{ exif_error_docref */
1567 : static void exif_error_docref(const char *docref EXIFERR_DC, const image_info_type *ImageInfo, int type, const char *format, ...)
1568 3 : {
1569 : va_list args;
1570 :
1571 3 : va_start(args, format);
1572 : #ifdef EXIF_DEBUG
1573 : {
1574 : char *buf;
1575 :
1576 : spprintf(&buf, 0, "%s(%d): %s", _file, _line, format);
1577 : php_verror(docref, ImageInfo->FileName?ImageInfo->FileName:"", type, buf, args TSRMLS_CC);
1578 : efree(buf);
1579 : }
1580 : #else
1581 3 : php_verror(docref, ImageInfo->FileName?ImageInfo->FileName:"", type, format, args TSRMLS_CC);
1582 : #endif
1583 3 : va_end(args);
1584 3 : }
1585 : /* }}} */
1586 :
1587 : /* {{{ jpeg_sof_info
1588 : */
1589 : typedef struct {
1590 : int bits_per_sample;
1591 : size_t width;
1592 : size_t height;
1593 : int num_components;
1594 : } jpeg_sof_info;
1595 : /* }}} */
1596 :
1597 : /* {{{ exif_file_sections_add
1598 : Add a file_section to image_info
1599 : returns the used block or -1. if size>0 and data == NULL buffer of size is allocated
1600 : */
1601 : static int exif_file_sections_add(image_info_type *ImageInfo, int type, size_t size, uchar *data)
1602 215 : {
1603 : file_section *tmp;
1604 215 : int count = ImageInfo->file.count;
1605 :
1606 215 : tmp = safe_erealloc(ImageInfo->file.list, (count+1), sizeof(file_section), 0);
1607 215 : ImageInfo->file.list = tmp;
1608 215 : ImageInfo->file.list[count].type = 0xFFFF;
1609 215 : ImageInfo->file.list[count].data = NULL;
1610 215 : ImageInfo->file.list[count].size = 0;
1611 215 : ImageInfo->file.count = count+1;
1612 215 : if (!size) {
1613 0 : data = NULL;
1614 215 : } else if (data == NULL) {
1615 215 : data = safe_emalloc(size, 1, 0);
1616 : }
1617 215 : ImageInfo->file.list[count].type = type;
1618 215 : ImageInfo->file.list[count].data = data;
1619 215 : ImageInfo->file.list[count].size = size;
1620 215 : return count;
1621 : }
1622 : /* }}} */
1623 :
1624 : /* {{{ exif_file_sections_realloc
1625 : Reallocate a file section returns 0 on success and -1 on failure
1626 : */
1627 : static int exif_file_sections_realloc(image_info_type *ImageInfo, int section_index, size_t size TSRMLS_DC)
1628 38 : {
1629 : void *tmp;
1630 :
1631 : /* This is not a malloc/realloc check. It is a plausibility check for the
1632 : * function parameters (requirements engineering).
1633 : */
1634 38 : if (section_index >= ImageInfo->file.count) {
1635 0 : EXIF_ERRLOG_FSREALLOC(ImageInfo)
1636 0 : return -1;
1637 : }
1638 38 : tmp = safe_erealloc(ImageInfo->file.list[section_index].data, 1, size, 0);
1639 38 : ImageInfo->file.list[section_index].data = tmp;
1640 38 : ImageInfo->file.list[section_index].size = size;
1641 38 : return 0;
1642 : }
1643 : /* }}} */
1644 :
1645 : /* {{{ exif_file_section_free
1646 : Discard all file_sections in ImageInfo
1647 : */
1648 : static int exif_file_sections_free(image_info_type *ImageInfo)
1649 30 : {
1650 : int i;
1651 :
1652 30 : if (ImageInfo->file.count) {
1653 245 : for (i=0; i<ImageInfo->file.count; i++) {
1654 215 : EFREE_IF(ImageInfo->file.list[i].data);
1655 : }
1656 : }
1657 30 : EFREE_IF(ImageInfo->file.list);
1658 30 : ImageInfo->file.count = 0;
1659 30 : return TRUE;
1660 : }
1661 : /* }}} */
1662 :
1663 : /* {{{ exif_iif_add_value
1664 : Add a value to image_info
1665 : */
1666 : static void exif_iif_add_value(image_info_type *image_info, int section_index, char *name, int tag, int format, int length, void* value, int motorola_intel TSRMLS_DC)
1667 465 : {
1668 : size_t idex;
1669 : void *vptr;
1670 : image_info_value *info_value;
1671 : image_info_data *info_data;
1672 : image_info_data *list;
1673 :
1674 465 : if (length < 0) {
1675 0 : return;
1676 : }
1677 :
1678 465 : list = safe_erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1), sizeof(image_info_data), 0);
1679 465 : image_info->info_list[section_index].list = list;
1680 :
1681 465 : info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
1682 465 : memset(info_data, 0, sizeof(image_info_data));
1683 465 : info_data->tag = tag;
1684 465 : info_data->format = format;
1685 465 : info_data->length = length;
1686 465 : info_data->name = estrdup(name);
1687 465 : info_value = &info_data->value;
1688 :
1689 465 : switch (format) {
1690 : case TAG_FMT_STRING:
1691 163 : if (value) {
1692 163 : length = php_strnlen(value, length);
1693 163 : if (PG(magic_quotes_runtime)) {
1694 5 : info_value->s = php_addslashes(value, length, &length, 0 TSRMLS_CC);
1695 : } else {
1696 158 : info_value->s = estrndup(value, length);
1697 : }
1698 163 : info_data->length = length;
1699 : } else {
1700 0 : info_data->length = 0;
1701 0 : info_value->s = estrdup("");
1702 : }
1703 163 : break;
1704 :
1705 : default:
1706 : /* Standard says more types possible but skip them...
1707 : * but allow users to handle data if they know how to
1708 : * So not return but use type UNDEFINED
1709 : * return;
1710 : */
1711 0 : info_data->tag = TAG_FMT_UNDEFINED;/* otherwise not freed from memory */
1712 : case TAG_FMT_SBYTE:
1713 : case TAG_FMT_BYTE:
1714 : /* in contrast to strings bytes do not need to allocate buffer for NULL if length==0 */
1715 21 : if (!length)
1716 0 : break;
1717 : case TAG_FMT_UNDEFINED:
1718 25 : if (value) {
1719 : /* do not recompute length here */
1720 25 : if (PG(magic_quotes_runtime)) {
1721 0 : info_value->s = php_addslashes(value, length, &length, 0 TSRMLS_CC);
1722 : } else {
1723 25 : info_value->s = estrndup(value, length);
1724 : }
1725 25 : info_data->length = length;
1726 : } else {
1727 0 : info_data->length = 0;
1728 0 : info_value->s = estrdup("");
1729 : }
1730 25 : break;
1731 :
1732 : case TAG_FMT_USHORT:
1733 : case TAG_FMT_ULONG:
1734 : case TAG_FMT_URATIONAL:
1735 : case TAG_FMT_SSHORT:
1736 : case TAG_FMT_SLONG:
1737 : case TAG_FMT_SRATIONAL:
1738 : case TAG_FMT_SINGLE:
1739 : case TAG_FMT_DOUBLE:
1740 277 : if (length==0) {
1741 0 : break;
1742 : } else
1743 277 : if (length>1) {
1744 33 : info_value->list = safe_emalloc(length, sizeof(image_info_value), 0);
1745 : } else {
1746 244 : info_value = &info_data->value;
1747 : }
1748 7505 : for (idex=0,vptr=value; idex<(size_t)length; idex++,vptr=(char *) vptr + php_tiff_bytes_per_format[format]) {
1749 7228 : if (length>1) {
1750 6984 : info_value = &info_data->value.list[idex];
1751 : }
1752 7228 : switch (format) {
1753 : case TAG_FMT_USHORT:
1754 7043 : info_value->u = php_ifd_get16u(vptr, motorola_intel);
1755 7043 : break;
1756 :
1757 : case TAG_FMT_ULONG:
1758 50 : info_value->u = php_ifd_get32u(vptr, motorola_intel);
1759 50 : break;
1760 :
1761 : case TAG_FMT_URATIONAL:
1762 135 : info_value->ur.num = php_ifd_get32u(vptr, motorola_intel);
1763 135 : info_value->ur.den = php_ifd_get32u(4+(char *)vptr, motorola_intel);
1764 135 : break;
1765 :
1766 : case TAG_FMT_SSHORT:
1767 0 : info_value->i = php_ifd_get16s(vptr, motorola_intel);
1768 0 : break;
1769 :
1770 : case TAG_FMT_SLONG:
1771 0 : info_value->i = php_ifd_get32s(vptr, motorola_intel);
1772 0 : break;
1773 :
1774 : case TAG_FMT_SRATIONAL:
1775 0 : info_value->sr.num = php_ifd_get32u(vptr, motorola_intel);
1776 0 : info_value->sr.den = php_ifd_get32u(4+(char *)vptr, motorola_intel);
1777 0 : break;
1778 :
1779 : case TAG_FMT_SINGLE:
1780 : #ifdef EXIF_DEBUG
1781 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Found value of type single");
1782 : #endif
1783 0 : info_value->f = *(float *)value;
1784 :
1785 : case TAG_FMT_DOUBLE:
1786 : #ifdef EXIF_DEBUG
1787 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Found value of type double");
1788 : #endif
1789 0 : info_value->d = *(double *)value;
1790 : break;
1791 : }
1792 : }
1793 : }
1794 465 : image_info->sections_found |= 1<<section_index;
1795 465 : image_info->info_list[section_index].count++;
1796 : }
1797 : /* }}} */
1798 :
1799 : /* {{{ exif_iif_add_tag
1800 : Add a tag from IFD to image_info
1801 : */
1802 : static void exif_iif_add_tag(image_info_type *image_info, int section_index, char *name, int tag, int format, size_t length, void* value TSRMLS_DC)
1803 465 : {
1804 465 : exif_iif_add_value(image_info, section_index, name, tag, format, (int)length, value, image_info->motorola_intel TSRMLS_CC);
1805 465 : }
1806 : /* }}} */
1807 :
1808 : /* {{{ exif_iif_add_int
1809 : Add an int value to image_info
1810 : */
1811 : static void exif_iif_add_int(image_info_type *image_info, int section_index, char *name, int value TSRMLS_DC)
1812 200 : {
1813 : image_info_data *info_data;
1814 : image_info_data *list;
1815 :
1816 200 : list = safe_erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1), sizeof(image_info_data), 0);
1817 200 : image_info->info_list[section_index].list = list;
1818 :
1819 200 : info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
1820 200 : info_data->tag = TAG_NONE;
1821 200 : info_data->format = TAG_FMT_SLONG;
1822 200 : info_data->length = 1;
1823 200 : info_data->name = estrdup(name);
1824 200 : info_data->value.i = value;
1825 200 : image_info->sections_found |= 1<<section_index;
1826 200 : image_info->info_list[section_index].count++;
1827 200 : }
1828 : /* }}} */
1829 :
1830 : /* {{{ exif_iif_add_str
1831 : Add a string value to image_info MUST BE NUL TERMINATED
1832 : */
1833 : static void exif_iif_add_str(image_info_type *image_info, int section_index, char *name, char *value TSRMLS_DC)
1834 218 : {
1835 : image_info_data *info_data;
1836 : image_info_data *list;
1837 :
1838 218 : if (value) {
1839 200 : list = safe_erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1), sizeof(image_info_data), 0);
1840 200 : image_info->info_list[section_index].list = list;
1841 200 : info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
1842 200 : info_data->tag = TAG_NONE;
1843 200 : info_data->format = TAG_FMT_STRING;
1844 200 : info_data->length = 1;
1845 200 : info_data->name = estrdup(name);
1846 200 : if (PG(magic_quotes_runtime)) {
1847 9 : info_data->value.s = php_addslashes(value, strlen(value), NULL, 0 TSRMLS_CC);
1848 : } else {
1849 191 : info_data->value.s = estrdup(value);
1850 : }
1851 200 : image_info->sections_found |= 1<<section_index;
1852 200 : image_info->info_list[section_index].count++;
1853 : }
1854 218 : }
1855 : /* }}} */
1856 :
1857 : /* {{{ exif_iif_add_fmt
1858 : Add a format string value to image_info MUST BE NUL TERMINATED
1859 : */
1860 : static void exif_iif_add_fmt(image_info_type *image_info, int section_index, char *name TSRMLS_DC, char *value, ...)
1861 35 : {
1862 : char *tmp;
1863 : va_list arglist;
1864 :
1865 35 : va_start(arglist, value);
1866 35 : if (value) {
1867 35 : vspprintf(&tmp, 0, value, arglist);
1868 35 : exif_iif_add_str(image_info, section_index, name, tmp TSRMLS_CC);
1869 35 : efree(tmp);
1870 : }
1871 35 : va_end(arglist);
1872 35 : }
1873 : /* }}} */
1874 :
1875 : /* {{{ exif_iif_add_str
1876 : Add a string value to image_info MUST BE NUL TERMINATED
1877 : */
1878 : static void exif_iif_add_buffer(image_info_type *image_info, int section_index, char *name, int length, char *value TSRMLS_DC)
1879 5 : {
1880 : image_info_data *info_data;
1881 : image_info_data *list;
1882 :
1883 5 : if (value) {
1884 5 : list = safe_erealloc(image_info->info_list[section_index].list, (image_info->info_list[section_index].count+1), sizeof(image_info_data), 0);
1885 5 : image_info->info_list[section_index].list = list;
1886 5 : info_data = &image_info->info_list[section_index].list[image_info->info_list[section_index].count];
1887 5 : info_data->tag = TAG_NONE;
1888 5 : info_data->format = TAG_FMT_UNDEFINED;
1889 5 : info_data->length = length;
1890 5 : info_data->name = estrdup(name);
1891 5 : if (PG(magic_quotes_runtime)) {
1892 : #ifdef EXIF_DEBUG
1893 : exif_error_docref(NULL EXIFERR_CC, image_info, E_NOTICE, "Adding %s as buffer%s", name, exif_char_dump(value, length, 0));
1894 : #endif
1895 1 : info_data->value.s = php_addslashes(value, length, &length, 0 TSRMLS_CC);
1896 1 : info_data->length = length;
1897 : } else {
1898 4 : info_data->value.s = safe_emalloc(length, 1, 1);
1899 4 : memcpy(info_data->value.s, value, length);
1900 4 : info_data->value.s[length] = 0;
1901 : }
1902 5 : image_info->sections_found |= 1<<section_index;
1903 5 : image_info->info_list[section_index].count++;
1904 : }
1905 5 : }
1906 : /* }}} */
1907 :
1908 : /* {{{ exif_iif_free
1909 : Free memory allocated for image_info
1910 : */
1911 420 : static void exif_iif_free(image_info_type *image_info, int section_index) {
1912 : int i;
1913 : void *f; /* faster */
1914 :
1915 420 : if (image_info->info_list[section_index].count) {
1916 987 : for (i=0; i < image_info->info_list[section_index].count; i++) {
1917 870 : if ((f=image_info->info_list[section_index].list[i].name) != NULL) {
1918 870 : efree(f);
1919 : }
1920 870 : switch(image_info->info_list[section_index].list[i].format) {
1921 : case TAG_FMT_SBYTE:
1922 : case TAG_FMT_BYTE:
1923 : /* in contrast to strings bytes do not need to allocate buffer for NULL if length==0 */
1924 21 : if (image_info->info_list[section_index].list[i].length<1)
1925 0 : break;
1926 : default:
1927 : case TAG_FMT_UNDEFINED:
1928 : case TAG_FMT_STRING:
1929 393 : if ((f=image_info->info_list[section_index].list[i].value.s) != NULL) {
1930 393 : efree(f);
1931 : }
1932 393 : break;
1933 :
1934 : case TAG_FMT_USHORT:
1935 : case TAG_FMT_ULONG:
1936 : case TAG_FMT_URATIONAL:
1937 : case TAG_FMT_SSHORT:
1938 : case TAG_FMT_SLONG:
1939 : case TAG_FMT_SRATIONAL:
1940 : case TAG_FMT_SINGLE:
1941 : case TAG_FMT_DOUBLE:
1942 : /* nothing to do here */
1943 477 : if (image_info->info_list[section_index].list[i].length > 1) {
1944 33 : if ((f=image_info->info_list[section_index].list[i].value.list) != NULL) {
1945 33 : efree(f);
1946 : }
1947 : }
1948 : break;
1949 : }
1950 : }
1951 : }
1952 420 : EFREE_IF(image_info->info_list[section_index].list);
1953 420 : }
1954 : /* }}} */
1955 :
1956 : /* {{{ add_assoc_image_info
1957 : * Add image_info to associative array value. */
1958 : static void add_assoc_image_info(zval *value, int sub_array, image_info_type *image_info, int section_index TSRMLS_DC)
1959 364 : {
1960 : char buffer[64], *val, *name, uname[64];
1961 364 : int i, ap, l, b, idx=0, unknown=0;
1962 : #ifdef EXIF_DEBUG
1963 : int info_tag;
1964 : #endif
1965 : image_info_value *info_value;
1966 : image_info_data *info_data;
1967 364 : zval *tmpi, *array = NULL;
1968 :
1969 : #ifdef EXIF_DEBUG
1970 : /* php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Adding %d infos from section %s", image_info->info_list[section_index].count, exif_get_sectionname(section_index));*/
1971 : #endif
1972 364 : if (image_info->info_list[section_index].count) {
1973 114 : if (sub_array) {
1974 49 : MAKE_STD_ZVAL(tmpi);
1975 49 : array_init(tmpi);
1976 : } else {
1977 65 : tmpi = value;
1978 : }
1979 :
1980 977 : for(i=0; i<image_info->info_list[section_index].count; i++) {
1981 863 : info_data = &image_info->info_list[section_index].list[i];
1982 : #ifdef EXIF_DEBUG
1983 : info_tag = info_data->tag; /* conversion */
1984 : #endif
1985 863 : info_value = &info_data->value;
1986 863 : if (!(name = info_data->name)) {
1987 0 : snprintf(uname, sizeof(uname), "%d", unknown++);
1988 0 : name = uname;
1989 : }
1990 : #ifdef EXIF_DEBUG
1991 : /* php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Adding infos: tag(0x%04X,%12s,L=0x%04X): %s", info_tag, exif_get_tagname(info_tag, buffer, -12, exif_get_tag_table(section_index) TSRMLS_CC), info_data->length, info_data->format==TAG_FMT_STRING?(info_value&&info_value->s?info_value->s:"<no data>"):exif_get_tagformat(info_data->format));*/
1992 : #endif
1993 863 : if (info_data->length==0) {
1994 0 : add_assoc_null(tmpi, name);
1995 : } else {
1996 863 : switch (info_data->format) {
1997 : default:
1998 : /* Standard says more types possible but skip them...
1999 : * but allow users to handle data if they know how to
2000 : * So not return but use type UNDEFINED
2001 : * return;
2002 : */
2003 : case TAG_FMT_BYTE:
2004 : case TAG_FMT_SBYTE:
2005 : case TAG_FMT_UNDEFINED:
2006 30 : if (!info_value->s) {
2007 0 : add_assoc_stringl(tmpi, name, "", 0, 1);
2008 : } else {
2009 30 : add_assoc_stringl(tmpi, name, info_value->s, info_data->length, 1);
2010 : }
2011 30 : break;
2012 :
2013 : case TAG_FMT_STRING:
2014 358 : if (!(val = info_value->s)) {
2015 0 : val = "";
2016 : }
2017 358 : if (section_index==SECTION_COMMENT) {
2018 15 : add_index_string(tmpi, idx++, val, 1);
2019 : } else {
2020 343 : add_assoc_string(tmpi, name, val, 1);
2021 : }
2022 358 : break;
2023 :
2024 : case TAG_FMT_URATIONAL:
2025 : case TAG_FMT_SRATIONAL:
2026 : /*case TAG_FMT_BYTE:
2027 : case TAG_FMT_SBYTE:*/
2028 : case TAG_FMT_USHORT:
2029 : case TAG_FMT_SSHORT:
2030 : case TAG_FMT_SINGLE:
2031 : case TAG_FMT_DOUBLE:
2032 : case TAG_FMT_ULONG:
2033 : case TAG_FMT_SLONG:
2034 : /* now the rest, first see if it becomes an array */
2035 475 : if ((l = info_data->length) > 1) {
2036 33 : array = NULL;
2037 33 : MAKE_STD_ZVAL(array);
2038 33 : array_init(array);
2039 : }
2040 7901 : for(ap=0; ap<l; ap++) {
2041 7426 : if (l>1) {
2042 6984 : info_value = &info_data->value.list[ap];
2043 : }
2044 7426 : switch (info_data->format) {
2045 : case TAG_FMT_BYTE:
2046 0 : if (l>1) {
2047 0 : info_value = &info_data->value;
2048 0 : for (b=0;b<l;b++) {
2049 0 : add_index_long(array, b, (int)(info_value->s[b]));
2050 : }
2051 0 : break;
2052 : }
2053 : case TAG_FMT_USHORT:
2054 : case TAG_FMT_ULONG:
2055 7091 : if (l==1) {
2056 179 : add_assoc_long(tmpi, name, (int)info_value->u);
2057 : } else {
2058 6912 : add_index_long(array, ap, (int)info_value->u);
2059 : }
2060 7091 : break;
2061 :
2062 : case TAG_FMT_URATIONAL:
2063 135 : snprintf(buffer, sizeof(buffer), "%i/%i", info_value->ur.num, info_value->ur.den);
2064 135 : if (l==1) {
2065 63 : add_assoc_string(tmpi, name, buffer, 1);
2066 : } else {
2067 72 : add_index_string(array, ap, buffer, 1);
2068 : }
2069 135 : break;
2070 :
2071 : case TAG_FMT_SBYTE:
2072 0 : if (l>1) {
2073 0 : info_value = &info_data->value;
2074 0 : for (b=0;b<l;b++) {
2075 0 : add_index_long(array, ap, (int)info_value->s[b]);
2076 : }
2077 0 : break;
2078 : }
2079 : case TAG_FMT_SSHORT:
2080 : case TAG_FMT_SLONG:
2081 200 : if (l==1) {
2082 200 : add_assoc_long(tmpi, name, info_value->i);
2083 : } else {
2084 0 : add_index_long(array, ap, info_value->i);
2085 : }
2086 200 : break;
2087 :
2088 : case TAG_FMT_SRATIONAL:
2089 0 : snprintf(buffer, sizeof(buffer), "%i/%i", info_value->sr.num, info_value->sr.den);
2090 0 : if (l==1) {
2091 0 : add_assoc_string(tmpi, name, buffer, 1);
2092 : } else {
2093 0 : add_index_string(array, ap, buffer, 1);
2094 : }
2095 0 : break;
2096 :
2097 : case TAG_FMT_SINGLE:
2098 0 : if (l==1) {
2099 0 : add_assoc_double(tmpi, name, info_value->f);
2100 : } else {
2101 0 : add_index_double(array, ap, info_value->f);
2102 : }
2103 0 : break;
2104 :
2105 : case TAG_FMT_DOUBLE:
2106 0 : if (l==1) {
2107 0 : add_assoc_double(tmpi, name, info_value->d);
2108 : } else {
2109 0 : add_index_double(array, ap, info_value->d);
2110 : }
2111 : break;
2112 : }
2113 7426 : info_value = &info_data->value.list[ap];
2114 : }
2115 475 : if (l>1) {
2116 33 : add_assoc_zval(tmpi, name, array);
2117 : }
2118 : break;
2119 : }
2120 : }
2121 : }
2122 114 : if (sub_array) {
2123 49 : add_assoc_zval(value, exif_get_sectionname(section_index), tmpi);
2124 : }
2125 : }
2126 364 : }
2127 : /* }}} */
2128 :
2129 : /* {{{ Markers
2130 : JPEG markers consist of one or more 0xFF bytes, followed by a marker
2131 : code byte (which is not an FF). Here are the marker codes of interest
2132 : in this program. (See jdmarker.c for a more complete list.)
2133 : */
2134 :
2135 : #define M_TEM 0x01 /* temp for arithmetic coding */
2136 : #define M_RES 0x02 /* reserved */
2137 : #define M_SOF0 0xC0 /* Start Of Frame N */
2138 : #define M_SOF1 0xC1 /* N indicates which compression process */
2139 : #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
2140 : #define M_SOF3 0xC3
2141 : #define M_DHT 0xC4
2142 : #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
2143 : #define M_SOF6 0xC6
2144 : #define M_SOF7 0xC7
2145 : #define M_JPEG 0x08 /* reserved for extensions */
2146 : #define M_SOF9 0xC9
2147 : #define M_SOF10 0xCA
2148 : #define M_SOF11 0xCB
2149 : #define M_DAC 0xCC /* arithmetic table */
2150 : #define M_SOF13 0xCD
2151 : #define M_SOF14 0xCE
2152 : #define M_SOF15 0xCF
2153 : #define M_RST0 0xD0 /* restart segment */
2154 : #define M_RST1 0xD1
2155 : #define M_RST2 0xD2
2156 : #define M_RST3 0xD3
2157 : #define M_RST4 0xD4
2158 : #define M_RST5 0xD5
2159 : #define M_RST6 0xD6
2160 : #define M_RST7 0xD7
2161 : #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
2162 : #define M_EOI 0xD9 /* End Of Image (end of datastream) */
2163 : #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
2164 : #define M_DQT 0xDB
2165 : #define M_DNL 0xDC
2166 : #define M_DRI 0xDD
2167 : #define M_DHP 0xDE
2168 : #define M_EXP 0xDF
2169 : #define M_APP0 0xE0 /* JPEG: 'JFIFF' AND (additional 'JFXX') */
2170 : #define M_EXIF 0xE1 /* Exif Attribute Information */
2171 : #define M_APP2 0xE2 /* Flash Pix Extension Data? */
2172 : #define M_APP3 0xE3
2173 : #define M_APP4 0xE4
2174 : #define M_APP5 0xE5
2175 : #define M_APP6 0xE6
2176 : #define M_APP7 0xE7
2177 : #define M_APP8 0xE8
2178 : #define M_APP9 0xE9
2179 : #define M_APP10 0xEA
2180 : #define M_APP11 0xEB
2181 : #define M_APP12 0xEC
2182 : #define M_APP13 0xED /* IPTC International Press Telecommunications Council */
2183 : #define M_APP14 0xEE /* Software, Copyright? */
2184 : #define M_APP15 0xEF
2185 : #define M_JPG0 0xF0
2186 : #define M_JPG1 0xF1
2187 : #define M_JPG2 0xF2
2188 : #define M_JPG3 0xF3
2189 : #define M_JPG4 0xF4
2190 : #define M_JPG5 0xF5
2191 : #define M_JPG6 0xF6
2192 : #define M_JPG7 0xF7
2193 : #define M_JPG8 0xF8
2194 : #define M_JPG9 0xF9
2195 : #define M_JPG10 0xFA
2196 : #define M_JPG11 0xFB
2197 : #define M_JPG12 0xFC
2198 : #define M_JPG13 0xFD
2199 : #define M_COM 0xFE /* COMment */
2200 :
2201 : #define M_PSEUDO 0x123 /* Extra value. */
2202 :
2203 : /* }}} */
2204 :
2205 : /* {{{ jpeg2000 markers
2206 : */
2207 : /* Markers x30 - x3F do not have a segment */
2208 : /* Markers x00, x01, xFE, xC0 - xDF ISO/IEC 10918-1 -> M_<xx> */
2209 : /* Markers xF0 - xF7 ISO/IEC 10918-3 */
2210 : /* Markers xF7 - xF8 ISO/IEC 14495-1 */
2211 : /* XY=Main/Tile-header:(R:required, N:not_allowed, O:optional, L:last_marker) */
2212 : #define JC_SOC 0x4F /* NN, Start of codestream */
2213 : #define JC_SIZ 0x51 /* RN, Image and tile size */
2214 : #define JC_COD 0x52 /* RO, Codeing style defaulte */
2215 : #define JC_COC 0x53 /* OO, Coding style component */
2216 : #define JC_TLM 0x55 /* ON, Tile part length main header */
2217 : #define JC_PLM 0x57 /* ON, Packet length main header */
2218 : #define JC_PLT 0x58 /* NO, Packet length tile part header */
2219 : #define JC_QCD 0x5C /* RO, Quantization default */
2220 : #define JC_QCC 0x5D /* OO, Quantization component */
2221 : #define JC_RGN 0x5E /* OO, Region of interest */
2222 : #define JC_POD 0x5F /* OO, Progression order default */
2223 : #define JC_PPM 0x60 /* ON, Packed packet headers main header */
2224 : #define JC_PPT 0x61 /* NO, Packet packet headers tile part header */
2225 : #define JC_CME 0x64 /* OO, Comment: "LL E <text>" E=0:binary, E=1:ascii */
2226 : #define JC_SOT 0x90 /* NR, Start of tile */
2227 : #define JC_SOP 0x91 /* NO, Start of packeter default */
2228 : #define JC_EPH 0x92 /* NO, End of packet header */
2229 : #define JC_SOD 0x93 /* NL, Start of data */
2230 : #define JC_EOC 0xD9 /* NN, End of codestream */
2231 : /* }}} */
2232 :
2233 : /* {{{ exif_process_COM
2234 : Process a COM marker.
2235 : We want to print out the marker contents as legible text;
2236 : we must guard against random junk and varying newline representations.
2237 : */
2238 : static void exif_process_COM (image_info_type *image_info, char *value, size_t length TSRMLS_DC)
2239 18 : {
2240 18 : exif_iif_add_tag(image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_STRING, length-2, value+2 TSRMLS_CC);
2241 18 : }
2242 : /* }}} */
2243 :
2244 : /* {{{ exif_process_CME
2245 : Process a CME marker.
2246 : We want to print out the marker contents as legible text;
2247 : we must guard against random junk and varying newline representations.
2248 : */
2249 : #ifdef EXIF_JPEG2000
2250 : static void exif_process_CME (image_info_type *image_info, char *value, size_t length TSRMLS_DC)
2251 : {
2252 : if (length>3) {
2253 : switch(value[2]) {
2254 : case 0:
2255 : exif_iif_add_tag(image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_UNDEFINED, length, value TSRMLS_CC);
2256 : break;
2257 : case 1:
2258 : exif_iif_add_tag(image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_STRING, length, value);
2259 : break;
2260 : default:
2261 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Undefined JPEG2000 comment encoding");
2262 : break;
2263 : }
2264 : } else {
2265 : exif_iif_add_tag(image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_UNDEFINED, 0, NULL);
2266 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "JPEG2000 comment section too small");
2267 : }
2268 : }
2269 : #endif
2270 : /* }}} */
2271 :
2272 : /* {{{ exif_process_SOFn
2273 : * Process a SOFn marker. This is useful for the image dimensions */
2274 : static void exif_process_SOFn (uchar *Data, int marker, jpeg_sof_info *result)
2275 20 : {
2276 : /* 0xFF SOSn SectLen(2) Bits(1) Height(2) Width(2) Channels(1) 3*Channels (1) */
2277 20 : result->bits_per_sample = Data[2];
2278 20 : result->height = php_jpg_get16(Data+3);
2279 20 : result->width = php_jpg_get16(Data+5);
2280 20 : result->num_components = Data[7];
2281 :
2282 : /* switch (marker) {
2283 : case M_SOF0: process = "Baseline"; break;
2284 : case M_SOF1: process = "Extended sequential"; break;
2285 : case M_SOF2: process = "Progressive"; break;
2286 : case M_SOF3: process = "Lossless"; break;
2287 : case M_SOF5: process = "Differential sequential"; break;
2288 : case M_SOF6: process = "Differential progressive"; break;
2289 : case M_SOF7: process = "Differential lossless"; break;
2290 : case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
2291 : case M_SOF10: process = "Progressive, arithmetic coding"; break;
2292 : case M_SOF11: process = "Lossless, arithmetic coding"; break;
2293 : case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
2294 : case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
2295 : case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
2296 : default: process = "Unknown"; break;
2297 : }*/
2298 20 : }
2299 : /* }}} */
2300 :
2301 : /* forward declarations */
2302 : static int exif_process_IFD_in_JPEG(image_info_type *ImageInfo, char *dir_start, char *offset_base, size_t IFDlength, size_t displacement, int section_index TSRMLS_DC);
2303 : static int exif_process_IFD_TAG( image_info_type *ImageInfo, char *dir_entry, char *offset_base, size_t IFDlength, size_t displacement, int section_index, int ReadNextIFD, tag_table_type tag_table TSRMLS_DC);
2304 :
2305 : /* {{{ exif_get_markername
2306 : Get name of marker */
2307 : #ifdef EXIF_DEBUG
2308 : static char * exif_get_markername(int marker)
2309 : {
2310 : switch(marker) {
2311 : case 0xC0: return "SOF0";
2312 : case 0xC1: return "SOF1";
2313 : case 0xC2: return "SOF2";
2314 : case 0xC3: return "SOF3";
2315 : case 0xC4: return "DHT";
2316 : case 0xC5: return "SOF5";
2317 : case 0xC6: return "SOF6";
2318 : case 0xC7: return "SOF7";
2319 : case 0xC9: return "SOF9";
2320 : case 0xCA: return "SOF10";
2321 : case 0xCB: return "SOF11";
2322 : case 0xCD: return "SOF13";
2323 : case 0xCE: return "SOF14";
2324 : case 0xCF: return "SOF15";
2325 : case 0xD8: return "SOI";
2326 : case 0xD9: return "EOI";
2327 : case 0xDA: return "SOS";
2328 : case 0xDB: return "DQT";
2329 : case 0xDC: return "DNL";
2330 : case 0xDD: return "DRI";
2331 : case 0xDE: return "DHP";
2332 : case 0xDF: return "EXP";
2333 : case 0xE0: return "APP0";
2334 : case 0xE1: return "EXIF";
2335 : case 0xE2: return "FPIX";
2336 : case 0xE3: return "APP3";
2337 : case 0xE4: return "APP4";
2338 : case 0xE5: return "APP5";
2339 : case 0xE6: return "APP6";
2340 : case 0xE7: return "APP7";
2341 : case 0xE8: return "APP8";
2342 : case 0xE9: return "APP9";
2343 : case 0xEA: return "APP10";
2344 : case 0xEB: return "APP11";
2345 : case 0xEC: return "APP12";
2346 : case 0xED: return "APP13";
2347 : case 0xEE: return "APP14";
2348 : case 0xEF: return "APP15";
2349 : case 0xF0: return "JPG0";
2350 : case 0xFD: return "JPG13";
2351 : case 0xFE: return "COM";
2352 : case 0x01: return "TEM";
2353 : }
2354 : return "Unknown";
2355 : }
2356 : #endif
2357 : /* }}} */
2358 :
2359 : /* {{{ proto string exif_tagname(index)
2360 : Get headername for index or false if not defined */
2361 : PHP_FUNCTION(exif_tagname)
2362 31 : {
2363 : zval **p_num;
2364 31 : int tag, ac = ZEND_NUM_ARGS();
2365 : char *szTemp;
2366 :
2367 31 : if ((ac < 1 || ac > 1) || zend_get_parameters_ex(ac, &p_num) == FAILURE) {
2368 2 : WRONG_PARAM_COUNT;
2369 : }
2370 :
2371 29 : convert_to_long_ex(p_num);
2372 29 : tag = Z_LVAL_PP(p_num);
2373 29 : szTemp = exif_get_tagname(tag, NULL, 0, tag_table_IFD TSRMLS_CC);
2374 29 : if (tag<0 || !szTemp || !szTemp[0]) {
2375 26 : RETURN_BOOL(FALSE);
2376 : } else {
2377 3 : RETURN_STRING(szTemp, 1)
2378 : }
2379 : }
2380 : /* }}} */
2381 :
2382 : /* {{{ exif_ifd_make_value
2383 : * Create a value for an ifd from an info_data pointer */
2384 0 : static void* exif_ifd_make_value(image_info_data *info_data, int motorola_intel TSRMLS_DC) {
2385 : size_t byte_count;
2386 : char *value_ptr, *data_ptr;
2387 : size_t i;
2388 :
2389 : image_info_value *info_value;
2390 :
2391 0 : byte_count = php_tiff_bytes_per_format[info_data->format] * info_data->length;
2392 0 : value_ptr = safe_emalloc(max(byte_count, 4), 1, 0);
2393 0 : memset(value_ptr, 0, 4);
2394 0 : if (!info_data->length) {
2395 0 : return value_ptr;
2396 : }
2397 0 : if (info_data->format == TAG_FMT_UNDEFINED || info_data->format == TAG_FMT_STRING
2398 : || (byte_count>1 && (info_data->format == TAG_FMT_BYTE || info_data->format == TAG_FMT_SBYTE))
2399 : ) {
2400 0 : memmove(value_ptr, info_data->value.s, byte_count);
2401 0 : return value_ptr;
2402 0 : } else if (info_data->format == TAG_FMT_BYTE) {
2403 0 : *value_ptr = info_data->value.u;
2404 0 : return value_ptr;
2405 0 : } else if (info_data->format == TAG_FMT_SBYTE) {
2406 0 : *value_ptr = info_data->value.i;
2407 0 : return value_ptr;
2408 : } else {
2409 0 : data_ptr = value_ptr;
2410 0 : for(i=0; i<info_data->length; i++) {
2411 0 : if (info_data->length==1) {
2412 0 : info_value = &info_data->value;
2413 : } else {
2414 0 : info_value = &info_data->value.list[i];
2415 : }
2416 0 : switch(info_data->format) {
2417 : case TAG_FMT_USHORT:
2418 0 : php_ifd_set16u(data_ptr, info_value->u, motorola_intel);
2419 0 : data_ptr += 2;
2420 0 : break;
2421 : case TAG_FMT_ULONG:
2422 0 : php_ifd_set32u(data_ptr, info_value->u, motorola_intel);
2423 0 : data_ptr += 4;
2424 0 : break;
2425 : case TAG_FMT_SSHORT:
2426 0 : php_ifd_set16u(data_ptr, info_value->i, motorola_intel);
2427 0 : data_ptr += 2;
2428 0 : break;
2429 : case TAG_FMT_SLONG:
2430 0 : php_ifd_set32u(data_ptr, info_value->i, motorola_intel);
2431 0 : data_ptr += 4;
2432 0 : break;
2433 : case TAG_FMT_URATIONAL:
2434 0 : php_ifd_set32u(data_ptr, info_value->sr.num, motorola_intel);
2435 0 : php_ifd_set32u(data_ptr+4, info_value->sr.den, motorola_intel);
2436 0 : data_ptr += 8;
2437 0 : break;
2438 : case TAG_FMT_SRATIONAL:
2439 0 : php_ifd_set32u(data_ptr, info_value->ur.num, motorola_intel);
2440 0 : php_ifd_set32u(data_ptr+4, info_value->ur.den, motorola_intel);
2441 0 : data_ptr += 8;
2442 0 : break;
2443 : case TAG_FMT_SINGLE:
2444 0 : memmove(data_ptr, &info_data->value.f, byte_count);
2445 0 : data_ptr += 4;
2446 0 : break;
2447 : case TAG_FMT_DOUBLE:
2448 0 : memmove(data_ptr, &info_data->value.d, byte_count);
2449 0 : data_ptr += 8;
2450 : break;
2451 : }
2452 : }
2453 : }
2454 0 : return value_ptr;
2455 : }
2456 : /* }}} */
2457 :
2458 : /* {{{ exif_thumbnail_build
2459 : * Check and build thumbnail */
2460 1 : static void exif_thumbnail_build(image_info_type *ImageInfo TSRMLS_DC) {
2461 : size_t new_size, new_move, new_value;
2462 : char *new_data;
2463 : void *value_ptr;
2464 : int i, byte_count;
2465 : image_info_list *info_list;
2466 : image_info_data *info_data;
2467 : #ifdef EXIF_DEBUG
2468 : char tagname[64];
2469 : #endif
2470 :
2471 1 : if (!ImageInfo->read_thumbnail || !ImageInfo->Thumbnail.offset || !ImageInfo->Thumbnail.size) {
2472 0 : return; /* ignore this call */
2473 : }
2474 : #ifdef EXIF_DEBUG
2475 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: filetype = %d", ImageInfo->Thumbnail.filetype);
2476 : #endif
2477 1 : switch(ImageInfo->Thumbnail.filetype) {
2478 : default:
2479 : case IMAGE_FILETYPE_JPEG:
2480 : /* done */
2481 1 : break;
2482 : case IMAGE_FILETYPE_TIFF_II:
2483 : case IMAGE_FILETYPE_TIFF_MM:
2484 0 : info_list = &ImageInfo->info_list[SECTION_THUMBNAIL];
2485 0 : new_size = 8 + 2 + info_list->count * 12 + 4;
2486 : #ifdef EXIF_DEBUG
2487 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: size of signature + directory(%d): 0x%02X", info_list->count, new_size);
2488 : #endif
2489 0 : new_value= new_size; /* offset for ifd values outside ifd directory */
2490 0 : for (i=0; i<info_list->count; i++) {
2491 0 : info_data = &info_list->list[i];
2492 0 : byte_count = php_tiff_bytes_per_format[info_data->format] * info_data->length;
2493 0 : if (byte_count > 4) {
2494 0 : new_size += byte_count;
2495 : }
2496 : }
2497 0 : new_move = new_size;
2498 0 : new_data = safe_erealloc(ImageInfo->Thumbnail.data, 1, ImageInfo->Thumbnail.size, new_size);
2499 0 : ImageInfo->Thumbnail.data = new_data;
2500 0 : memmove(ImageInfo->Thumbnail.data + new_move, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
2501 0 : ImageInfo->Thumbnail.size += new_size;
2502 : /* fill in data */
2503 0 : if (ImageInfo->motorola_intel) {
2504 0 : memmove(new_data, "MM\x00\x2a\x00\x00\x00\x08", 8);
2505 : } else {
2506 0 : memmove(new_data, "II\x2a\x00\x08\x00\x00\x00", 8);
2507 : }
2508 0 : new_data += 8;
2509 0 : php_ifd_set16u(new_data, info_list->count, ImageInfo->motorola_intel);
2510 0 : new_data += 2;
2511 0 : for (i=0; i<info_list->count; i++) {
2512 0 : info_data = &info_list->list[i];
2513 0 : byte_count = php_tiff_bytes_per_format[info_data->format] * info_data->length;
2514 : #ifdef EXIF_DEBUG
2515 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: process tag(x%04X=%s): %s%s (%d bytes)", info_data->tag, exif_get_tagname(info_data->tag, tagname, -12, tag_table_IFD TSRMLS_CC), (info_data->length>1)&&info_data->format!=TAG_FMT_UNDEFINED&&info_data->format!=TAG_FMT_STRING?"ARRAY OF ":"", exif_get_tagformat(info_data->format), byte_count);
2516 : #endif
2517 0 : if (info_data->tag==TAG_STRIP_OFFSETS || info_data->tag==TAG_JPEG_INTERCHANGE_FORMAT) {
2518 0 : php_ifd_set16u(new_data + 0, info_data->tag, ImageInfo->motorola_intel);
2519 0 : php_ifd_set16u(new_data + 2, TAG_FMT_ULONG, ImageInfo->motorola_intel);
2520 0 : php_ifd_set32u(new_data + 4, 1, ImageInfo->motorola_intel);
2521 0 : php_ifd_set32u(new_data + 8, new_move, ImageInfo->motorola_intel);
2522 : } else {
2523 0 : php_ifd_set16u(new_data + 0, info_data->tag, ImageInfo->motorola_intel);
2524 0 : php_ifd_set16u(new_data + 2, info_data->format, ImageInfo->motorola_intel);
2525 0 : php_ifd_set32u(new_data + 4, info_data->length, ImageInfo->motorola_intel);
2526 0 : value_ptr = exif_ifd_make_value(info_data, ImageInfo->motorola_intel TSRMLS_CC);
2527 0 : if (byte_count <= 4) {
2528 0 : memmove(new_data+8, value_ptr, 4);
2529 : } else {
2530 0 : php_ifd_set32u(new_data+8, new_value, ImageInfo->motorola_intel);
2531 : #ifdef EXIF_DEBUG
2532 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: writing with value offset: 0x%04X + 0x%02X", new_value, byte_count);
2533 : #endif
2534 0 : memmove(ImageInfo->Thumbnail.data+new_value, value_ptr, byte_count);
2535 0 : new_value += byte_count;
2536 : }
2537 0 : efree(value_ptr);
2538 : }
2539 0 : new_data += 12;
2540 : }
2541 0 : memset(new_data, 0, 4); /* next ifd pointer */
2542 : #ifdef EXIF_DEBUG
2543 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: created");
2544 : #endif
2545 : break;
2546 : }
2547 : }
2548 : /* }}} */
2549 :
2550 : /* {{{ exif_thumbnail_extract
2551 : * Grab the thumbnail, corrected */
2552 1 : static void exif_thumbnail_extract(image_info_type *ImageInfo, char *offset, size_t length TSRMLS_DC) {
2553 1 : if (ImageInfo->Thumbnail.data) {
2554 0 : exif_error_docref("exif_read_data#error_mult_thumb" EXIFERR_CC, ImageInfo, E_WARNING, "Multiple possible thumbnails");
2555 0 : return; /* Should not happen */
2556 : }
2557 1 : if (!ImageInfo->read_thumbnail) {
2558 0 : return; /* ignore this call */
2559 : }
2560 : /* according to exif2.1, the thumbnail is not supposed to be greater than 64K */
2561 1 : if (ImageInfo->Thumbnail.size >= 65536
2562 : || ImageInfo->Thumbnail.size <= 0
2563 : || ImageInfo->Thumbnail.offset <= 0
2564 : ) {
2565 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Illegal thumbnail size/offset");
2566 0 : return;
2567 : }
2568 : /* Check to make sure we are not going to go past the ExifLength */
2569 1 : if ((ImageInfo->Thumbnail.offset + ImageInfo->Thumbnail.size) > length) {
2570 0 : EXIF_ERRLOG_THUMBEOF(ImageInfo)
2571 0 : return;
2572 : }
2573 1 : ImageInfo->Thumbnail.data = estrndup(offset + ImageInfo->Thumbnail.offset, ImageInfo->Thumbnail.size);
2574 1 : exif_thumbnail_build(ImageInfo TSRMLS_CC);
2575 : }
2576 : /* }}} */
2577 :
2578 : /* {{{ exif_process_undefined
2579 : * Copy a string/buffer in Exif header to a character string and return length of allocated buffer if any. */
2580 5 : static int exif_process_undefined(char **result, char *value, size_t byte_count TSRMLS_DC) {
2581 : /* we cannot use strlcpy - here the problem is that we have to copy NUL
2582 : * chars up to byte_count, we also have to add a single NUL character to
2583 : * force end of string.
2584 : * estrndup does not return length
2585 : */
2586 5 : if (byte_count) {
2587 5 : (*result) = estrndup(value, byte_count); /* NULL @ byte_count!!! */
2588 5 : return byte_count+1;
2589 : }
2590 0 : return 0;
2591 : }
2592 : /* }}} */
2593 :
2594 : /* {{{ exif_process_string_raw
2595 : * Copy a string in Exif header to a character string returns length of allocated buffer if any. */
2596 : #if !EXIF_USE_MBSTRING
2597 : static int exif_process_string_raw(char **result, char *value, size_t byte_count) {
2598 : /* we cannot use strlcpy - here the problem is that we have to copy NUL
2599 : * chars up to byte_count, we also have to add a single NUL character to
2600 : * force end of string.
2601 : */
2602 : if (byte_count) {
2603 : (*result) = safe_emalloc(byte_count, 1, 1);
2604 : memcpy(*result, value, byte_count);
2605 : (*result)[byte_count] = '\0';
2606 : return byte_count+1;
2607 : }
2608 : return 0;
2609 : }
2610 : #endif
2611 : /* }}} */
2612 :
2613 : /* {{{ exif_process_string
2614 : * Copy a string in Exif header to a character string and return length of allocated buffer if any.
2615 : * In contrast to exif_process_string this function does allways return a string buffer */
2616 5 : static int exif_process_string(char **result, char *value, size_t byte_count TSRMLS_DC) {
2617 : /* we cannot use strlcpy - here the problem is that we cannot use strlen to
2618 : * determin length of string and we cannot use strlcpy with len=byte_count+1
2619 : * because then we might get into an EXCEPTION if we exceed an allocated
2620 : * memory page...so we use php_strnlen in conjunction with memcpy and add the NUL
2621 : * char.
2622 : * estrdup would sometimes allocate more memory and does not return length
2623 : */
2624 5 : if ((byte_count=php_strnlen(value, byte_count)) > 0) {
2625 5 : return exif_process_undefined(result, value, byte_count TSRMLS_CC);
2626 : }
2627 0 : (*result) = estrndup("", 1); /* force empty string */
2628 0 : return byte_count+1;
2629 : }
2630 : /* }}} */
2631 :
2632 : /* {{{ exif_process_user_comment
2633 : * Process UserComment in IFD. */
2634 : static int exif_process_user_comment(image_info_type *ImageInfo, char **pszInfoPtr, char **pszEncoding, char *szValuePtr, int ByteCount TSRMLS_DC)
2635 6 : {
2636 : int a;
2637 :
2638 : #if EXIF_USE_MBSTRING
2639 : char *decode;
2640 : size_t len;;
2641 : #endif
2642 :
2643 6 : *pszEncoding = NULL;
2644 : /* Copy the comment */
2645 6 : if (ByteCount>=8) {
2646 6 : if (!memcmp(szValuePtr, "UNICODE\0", 8)) {
2647 1 : *pszEncoding = estrdup((const char*)szValuePtr);
2648 1 : szValuePtr = szValuePtr+8;
2649 1 : ByteCount -= 8;
2650 : #if EXIF_USE_MBSTRING
2651 : /* First try to detect BOM: ZERO WIDTH NOBREAK SPACE (FEFF 16)
2652 : * since we have no encoding support for the BOM yet we skip that.
2653 : */
2654 1 : if (!memcmp(szValuePtr, "\xFE\xFF", 2)) {
2655 0 : decode = "UCS-2BE";
2656 0 : szValuePtr = szValuePtr+2;
2657 0 : ByteCount -= 2;
2658 1 : } else if (!memcmp(szValuePtr, "\xFF\xFE", 2)) {
2659 0 : decode = "UCS-2LE";
2660 0 : szValuePtr = szValuePtr+2;
2661 0 : ByteCount -= 2;
2662 1 : } else if (ImageInfo->motorola_intel) {
2663 1 : decode = ImageInfo->decode_unicode_be;
2664 : } else {
2665 0 : decode = ImageInfo->decode_unicode_le;
2666 : }
2667 1 : *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, decode, &len TSRMLS_CC);
2668 1 : return len;
2669 : #else
2670 : return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
2671 : #endif
2672 : } else
2673 5 : if (!memcmp(szValuePtr, "ASCII\0\0\0", 8)) {
2674 5 : *pszEncoding = estrdup((const char*)szValuePtr);
2675 5 : szValuePtr = szValuePtr+8;
2676 5 : ByteCount -= 8;
2677 : } else
2678 0 : if (!memcmp(szValuePtr, "JIS\0\0\0\0\0", 8)) {
2679 : /* JIS should be tanslated to MB or we leave it to the user - leave it to the user */
2680 0 : *pszEncoding = estrdup((const char*)szValuePtr);
2681 0 : szValuePtr = szValuePtr+8;
2682 0 : ByteCount -= 8;
2683 : #if EXIF_USE_MBSTRING
2684 0 : if (ImageInfo->motorola_intel) {
2685 0 : *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_be, &len TSRMLS_CC);
2686 : } else {
2687 0 : *pszInfoPtr = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_jis, ImageInfo->decode_jis_le, &len TSRMLS_CC);
2688 : }
2689 0 : return len;
2690 : #else
2691 : return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount);
2692 : #endif
2693 : } else
2694 0 : if (!memcmp(szValuePtr, "\0\0\0\0\0\0\0\0", 8)) {
2695 : /* 8 NULL means undefined and should be ASCII... */
2696 0 : *pszEncoding = estrdup("UNDEFINED");
2697 0 : szValuePtr = szValuePtr+8;
2698 0 : ByteCount -= 8;
2699 : }
2700 : }
2701 :
2702 : /* Olympus has this padded with trailing spaces. Remove these first. */
2703 5 : if (ByteCount>0) {
2704 5 : for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) {
2705 0 : (szValuePtr)[a] = '\0';
2706 : }
2707 : }
2708 :
2709 : /* normal text without encoding */
2710 5 : exif_process_string(pszInfoPtr, szValuePtr, ByteCount TSRMLS_CC);
2711 5 : return strlen(*pszInfoPtr);
2712 : }
2713 : /* }}} */
2714 :
2715 : /* {{{ exif_process_unicode
2716 : * Process unicode field in IFD. */
2717 : static int exif_process_unicode(image_info_type *ImageInfo, xp_field_type *xp_field, int tag, char *szValuePtr, int ByteCount TSRMLS_DC)
2718 5 : {
2719 5 : xp_field->tag = tag;
2720 :
2721 : /* Copy the comment */
2722 : #if EXIF_USE_MBSTRING
2723 : /* What if MS supports big-endian with XP? */
2724 : /* if (ImageInfo->motorola_intel) {
2725 : xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_be, &xp_field->size TSRMLS_CC);
2726 : } else {
2727 : xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC);
2728 : }*/
2729 5 : xp_field->value = php_mb_convert_encoding(szValuePtr, ByteCount, ImageInfo->encode_unicode, ImageInfo->decode_unicode_le, &xp_field->size TSRMLS_CC);
2730 5 : return xp_field->size;
2731 : #else
2732 : xp_field->size = exif_process_string_raw(&xp_field->value, szValuePtr, ByteCount);
2733 : return xp_field->size;
2734 : #endif
2735 : }
2736 : /* }}} */
2737 :
2738 : /* {{{ exif_process_IFD_in_MAKERNOTE
2739 : * Process nested IFDs directories in Maker Note. */
2740 : static int exif_process_IFD_in_MAKERNOTE(image_info_type *ImageInfo, char * value_ptr, int value_len, char *offset_base, size_t IFDlength, size_t displacement TSRMLS_DC)
2741 0 : {
2742 0 : int de, i=0, section_index = SECTION_MAKERNOTE;
2743 : int NumDirEntries, old_motorola_intel, offset_diff;
2744 : const maker_note_type *maker_note;
2745 : char *dir_start;
2746 :
2747 0 : for (i=0; i<=sizeof(maker_note_array)/sizeof(maker_note_type); i++) {
2748 0 : if (i==sizeof(maker_note_array)/sizeof(maker_note_type))
2749 0 : return FALSE;
2750 0 : maker_note = maker_note_array+i;
2751 :
2752 : /*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "check (%s,%s)", maker_note->make?maker_note->make:"", maker_note->model?maker_note->model:"");*/
2753 0 : if (maker_note->make && (!ImageInfo->make || strcmp(maker_note->make, ImageInfo->make)))
2754 : continue;
2755 0 : if (maker_note->model && (!ImageInfo->model || strcmp(maker_note->model, ImageInfo->model)))
2756 : continue;
2757 0 : if (maker_note->id_string && strncmp(maker_note->id_string, value_ptr, maker_note->id_string_len))
2758 0 : continue;
2759 0 : break;
2760 : }
2761 :
2762 0 : dir_start = value_ptr + maker_note->offset;
2763 :
2764 : #ifdef EXIF_DEBUG
2765 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s @x%04X + 0x%04X=%d: %s", exif_get_sectionname(section_index), (int)dir_start-(int)offset_base+maker_note->offset+displacement, value_len, value_len, exif_char_dump(value_ptr, value_len, (int)dir_start-(int)offset_base+maker_note->offset+displacement));
2766 : #endif
2767 :
2768 0 : ImageInfo->sections_found |= FOUND_MAKERNOTE;
2769 :
2770 0 : old_motorola_intel = ImageInfo->motorola_intel;
2771 0 : switch (maker_note->byte_order) {
2772 : case MN_ORDER_INTEL:
2773 0 : ImageInfo->motorola_intel = 0;
2774 0 : break;
2775 : case MN_ORDER_MOTOROLA:
2776 0 : ImageInfo->motorola_intel = 1;
2777 : break;
2778 : default:
2779 : case MN_ORDER_NORMAL:
2780 : break;
2781 : }
2782 :
2783 0 : NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
2784 :
2785 0 : switch (maker_note->offset_mode) {
2786 : case MN_OFFSET_MAKER:
2787 0 : offset_base = value_ptr;
2788 0 : break;
2789 : case MN_OFFSET_GUESS:
2790 0 : offset_diff = 2 + NumDirEntries*12 + 4 - php_ifd_get32u(dir_start+10, ImageInfo->motorola_intel);
2791 : #ifdef EXIF_DEBUG
2792 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Using automatic offset correction: 0x%04X", ((int)dir_start-(int)offset_base+maker_note->offset+displacement) + offset_diff);
2793 : #endif
2794 0 : offset_base = value_ptr + offset_diff;
2795 : break;
2796 : default:
2797 : case MN_OFFSET_NORMAL:
2798 : break;
2799 : }
2800 :
2801 0 : if ((2+NumDirEntries*12) > value_len) {
2802 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: 2 + x%04X*12 = x%04X > x%04X", NumDirEntries, 2+NumDirEntries*12, value_len);
2803 0 : return FALSE;
2804 : }
2805 :
2806 0 : for (de=0;de<NumDirEntries;de++) {
2807 0 : if (!exif_process_IFD_TAG(ImageInfo, dir_start + 2 + 12 * de,
2808 : offset_base, IFDlength, displacement, section_index, 0, maker_note->tag_table TSRMLS_CC)) {
2809 0 : return FALSE;
2810 : }
2811 : }
2812 0 : ImageInfo->motorola_intel = old_motorola_intel;
2813 : /* NextDirOffset (must be NULL) = php_ifd_get32u(dir_start+2+12*de, ImageInfo->motorola_intel);*/
2814 : #ifdef EXIF_DEBUG
2815 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Subsection %s done", exif_get_sectionname(SECTION_MAKERNOTE));
2816 : #endif
2817 0 : return TRUE;
2818 : }
2819 : /* }}} */
2820 :
2821 : /* {{{ exif_process_IFD_TAG
2822 : * Process one of the nested IFDs directories. */
2823 : static int exif_process_IFD_TAG(image_info_type *ImageInfo, char *dir_entry, char *offset_base, size_t IFDlength, size_t displacement, int section_index, int ReadNextIFD, tag_table_type tag_table TSRMLS_DC)
2824 447 : {
2825 : size_t length;
2826 : int tag, format, components;
2827 447 : char *value_ptr, tagname[64], cbuf[32], *outside=NULL;
2828 : size_t byte_count, offset_val, fpos, fgot;
2829 : xp_field_type *tmp_xp;
2830 : #ifdef EXIF_DEBUG
2831 : char *dump_data;
2832 : int dump_free;
2833 : #endif /* EXIF_DEBUG */
2834 :
2835 : /* Protect against corrupt headers */
2836 447 : if (ImageInfo->ifd_nesting_level > MAX_IFD_NESTING_LEVEL) {
2837 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "corrupt EXIF header: maximum directory nesting level reached");
2838 0 : return FALSE;
2839 : }
2840 447 : ImageInfo->ifd_nesting_level++;
2841 :
2842 447 : tag = php_ifd_get16u(dir_entry, ImageInfo->motorola_intel);
2843 447 : format = php_ifd_get16u(dir_entry+2, ImageInfo->motorola_intel);
2844 447 : components = php_ifd_get32u(dir_entry+4, ImageInfo->motorola_intel);
2845 :
2846 447 : if (!format || format > NUM_FORMATS) {
2847 : /* (-1) catches illegal zero case as unsigned underflows to positive large. */
2848 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Illegal format code 0x%04X, suppose BYTE", tag, exif_get_tagname(tag, tagname, -12, tag_table TSRMLS_CC), format);
2849 0 : format = TAG_FMT_BYTE;
2850 : /*return TRUE;*/
2851 : }
2852 :
2853 447 : byte_count = components * php_tiff_bytes_per_format[format];
2854 :
2855 447 : if ((ssize_t)byte_count < 0) {
2856 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Illegal byte_count(%ld)", tag, exif_get_tagname(tag, tagname, -12, tag_table TSRMLS_CC), byte_count);
2857 0 : return FALSE;
2858 : }
2859 :
2860 447 : if (byte_count > 4) {
2861 226 : offset_val = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel);
2862 : /* If its bigger than 4 bytes, the dir entry contains an offset. */
2863 226 : value_ptr = offset_base+offset_val;
2864 226 : if (offset_val+byte_count > IFDlength || value_ptr < dir_entry) {
2865 : /* It is important to check for IMAGE_FILETYPE_TIFF
2866 : * JPEG does not use absolute pointers instead its pointers are
2867 : * relative to the start of the TIFF header in APP1 section. */
2868 87 : if (offset_val+byte_count>ImageInfo->FileSize || (ImageInfo->FileType!=IMAGE_FILETYPE_TIFF_II && ImageInfo->FileType!=IMAGE_FILETYPE_TIFF_MM && ImageInfo->FileType!=IMAGE_FILETYPE_JPEG)) {
2869 0 : if (value_ptr < dir_entry) {
2870 : /* we can read this if offset_val > 0 */
2871 : /* some files have their values in other parts of the file */
2872 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Illegal pointer offset(x%04X < x%04X)", tag, exif_get_tagname(tag, tagname, -12, tag_table TSRMLS_CC), offset_val, dir_entry);
2873 : } else {
2874 : /* this is for sure not allowed */
2875 : /* exception are IFD pointers */
2876 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Process tag(x%04X=%s): Illegal pointer offset(x%04X + x%04X = x%04X > x%04X)", tag, exif_get_tagname(tag, tagname, -12, tag_table TSRMLS_CC), offset_val, byte_count, offset_val+byte_count, IFDlength);
2877 : }
2878 0 : return FALSE;
2879 : }
2880 87 : if (byte_count>sizeof(cbuf)) {
2881 : /* mark as outside range and get buffer */
2882 9 : value_ptr = safe_emalloc(byte_count, 1, 0);
2883 9 : outside = value_ptr;
2884 : } else {
2885 : /* In most cases we only access a small range so
2886 : * it is faster to use a static buffer there
2887 : * BUT it offers also the possibility to have
2888 : * pointers read without the need to free them
2889 : * explicitley before returning. */
2890 78 : memset(&cbuf, 0, sizeof(cbuf));
2891 78 : value_ptr = cbuf;
2892 : }
2893 :
2894 87 : fpos = php_stream_tell(ImageInfo->infile);
2895 87 : php_stream_seek(ImageInfo->infile, offset_val, SEEK_SET);
2896 87 : fgot = php_stream_tell(ImageInfo->infile);
2897 87 : if (fgot!=offset_val) {
2898 0 : EFREE_IF(outside);
2899 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Wrong file pointer: 0x%08X != 0x08X", fgot, offset_val);
2900 0 : return FALSE;
2901 : }
2902 87 : fgot = php_stream_read(ImageInfo->infile, value_ptr, byte_count);
2903 87 : php_stream_seek(ImageInfo->infile, fpos, SEEK_SET);
2904 87 : if (fgot<byte_count) {
2905 0 : EFREE_IF(outside);
2906 0 : EXIF_ERRLOG_FILEEOF(ImageInfo)
2907 0 : return FALSE;
2908 : }
2909 : }
2910 : } else {
2911 : /* 4 bytes or less and value is in the dir entry itself */
2912 221 : value_ptr = dir_entry+8;
2913 221 : offset_val= value_ptr-offset_base;
2914 : }
2915 :
2916 447 : ImageInfo->sections_found |= FOUND_ANY_TAG;
2917 : #ifdef EXIF_DEBUG
2918 : dump_data = exif_dump_data(&dump_free, format, components, length, ImageInfo->motorola_intel, value_ptr TSRMLS_CC);
2919 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process tag(x%04X=%s,@x%04X + x%04X(=%d)): %s%s %s", tag, exif_get_tagname(tag, tagname, -12, tag_table TSRMLS_CC), offset_val+displacement, byte_count, byte_count, (components>1)&&format!=TAG_FMT_UNDEFINED&&format!=TAG_FMT_STRING?"ARRAY OF ":"", exif_get_tagformat(format), dump_data);
2920 : if (dump_free) {
2921 : efree(dump_data);
2922 : }
2923 : #endif
2924 447 : if (section_index==SECTION_THUMBNAIL) {
2925 12 : if (!ImageInfo->Thumbnail.data) {
2926 12 : switch(tag) {
2927 : case TAG_IMAGEWIDTH:
2928 : case TAG_COMP_IMAGE_WIDTH:
2929 0 : ImageInfo->Thumbnail.width = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
2930 0 : break;
2931 :
2932 : case TAG_IMAGEHEIGHT:
2933 : case TAG_COMP_IMAGE_HEIGHT:
2934 0 : ImageInfo->Thumbnail.height = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
2935 0 : break;
2936 :
2937 : case TAG_STRIP_OFFSETS:
2938 : case TAG_JPEG_INTERCHANGE_FORMAT:
2939 : /* accept both formats */
2940 6 : ImageInfo->Thumbnail.offset = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
2941 6 : break;
2942 :
2943 : case TAG_STRIP_BYTE_COUNTS:
2944 0 : if (ImageInfo->FileType == IMAGE_FILETYPE_TIFF_II || ImageInfo->FileType == IMAGE_FILETYPE_TIFF_MM) {
2945 0 : ImageInfo->Thumbnail.filetype = ImageInfo->FileType;
2946 : } else {
2947 : /* motorola is easier to read */
2948 0 : ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_TIFF_MM;
2949 : }
2950 0 : ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
2951 0 : break;
2952 :
2953 : case TAG_JPEG_INTERCHANGE_FORMAT_LEN:
2954 6 : if (ImageInfo->Thumbnail.filetype == IMAGE_FILETYPE_UNKNOWN) {
2955 6 : ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_JPEG;
2956 6 : ImageInfo->Thumbnail.size = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
2957 : }
2958 : break;
2959 : }
2960 : }
2961 : } else {
2962 435 : if (section_index==SECTION_IFD0 || section_index==SECTION_EXIF)
2963 351 : switch(tag) {
2964 : case TAG_COPYRIGHT:
2965 : /* check for "<photographer> NUL <editor> NUL" */
2966 23 : if (byte_count>1 && (length=php_strnlen(value_ptr, byte_count)) > 0) {
2967 23 : if (length<byte_count-1) {
2968 : /* When there are any characters after the first NUL */
2969 23 : ImageInfo->CopyrightPhotographer = estrdup(value_ptr);
2970 23 : ImageInfo->CopyrightEditor = estrdup(value_ptr+length+1);
2971 23 : spprintf(&ImageInfo->Copyright, 0, "%s, %s", value_ptr, value_ptr+length+1);
2972 : /* format = TAG_FMT_UNDEFINED; this musn't be ASCII */
2973 : /* but we are not supposed to change this */
2974 : /* keep in mind that image_info does not store editor value */
2975 : } else {
2976 0 : ImageInfo->Copyright = estrdup(value_ptr);
2977 : }
2978 : }
2979 23 : break;
2980 :
2981 : case TAG_USERCOMMENT:
2982 6 : ImageInfo->UserCommentLength = exif_process_user_comment(ImageInfo, &(ImageInfo->UserComment), &(ImageInfo->UserCommentEncoding), value_ptr, byte_count TSRMLS_CC);
2983 6 : break;
2984 :
2985 : case TAG_XP_TITLE:
2986 : case TAG_XP_COMMENTS:
2987 : case TAG_XP_AUTHOR:
2988 : case TAG_XP_KEYWORDS:
2989 : case TAG_XP_SUBJECT:
2990 5 : tmp_xp = (xp_field_type*)safe_erealloc(ImageInfo->xp_fields.list, (ImageInfo->xp_fields.count+1), sizeof(xp_field_type), 0);
2991 5 : ImageInfo->sections_found |= FOUND_WINXP;
2992 5 : ImageInfo->xp_fields.list = tmp_xp;
2993 5 : ImageInfo->xp_fields.count++;
2994 5 : exif_process_unicode(ImageInfo, &(ImageInfo->xp_fields.list[ImageInfo->xp_fields.count-1]), tag, value_ptr, byte_count TSRMLS_CC);
2995 5 : break;
2996 :
2997 : case TAG_FNUMBER:
2998 : /* Simplest way of expressing aperture, so I trust it the most.
2999 : (overwrite previously computed value if there is one) */
3000 7 : ImageInfo->ApertureFNumber = (float)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
3001 7 : break;
3002 :
3003 : case TAG_APERTURE:
3004 : case TAG_MAX_APERTURE:
3005 : /* More relevant info always comes earlier, so only use this field if we don't
3006 : have appropriate aperture information yet. */
3007 0 : if (ImageInfo->ApertureFNumber == 0) {
3008 0 : ImageInfo->ApertureFNumber
3009 : = (float)exp(exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC)*log(2)*0.5);
3010 : }
3011 0 : break;
3012 :
3013 : case TAG_SHUTTERSPEED:
3014 : /* More complicated way of expressing exposure time, so only use
3015 : this value if we don't already have it from somewhere else.
3016 : SHUTTERSPEED comes after EXPOSURE TIME
3017 : */
3018 0 : if (ImageInfo->ExposureTime == 0) {
3019 0 : ImageInfo->ExposureTime
3020 : = (float)(1/exp(exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC)*log(2)));
3021 : }
3022 0 : break;
3023 : case TAG_EXPOSURETIME:
3024 7 : ImageInfo->ExposureTime = -1;
3025 7 : break;
3026 :
3027 : case TAG_COMP_IMAGE_WIDTH:
3028 7 : ImageInfo->ExifImageWidth = exif_convert_any_to_int(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
3029 7 : break;
3030 :
3031 : case TAG_FOCALPLANE_X_RES:
3032 0 : ImageInfo->FocalplaneXRes = exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
3033 0 : break;
3034 :
3035 : case TAG_SUBJECT_DISTANCE:
3036 : /* Inidcates the distacne the autofocus camera is focused to.
3037 : Tends to be less accurate as distance increases. */
3038 0 : ImageInfo->Distance = (float)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC);
3039 0 : break;
3040 :
3041 : case TAG_FOCALPLANE_RESOLUTION_UNIT:
3042 0 : switch((int)exif_convert_any_format(value_ptr, format, ImageInfo->motorola_intel TSRMLS_CC)) {
3043 0 : case 1: ImageInfo->FocalplaneUnits = 25.4; break; /* inch */
3044 : case 2:
3045 : /* According to the information I was using, 2 measn meters.
3046 : But looking at the Cannon powershot's files, inches is the only
3047 : sensible value. */
3048 0 : ImageInfo->FocalplaneUnits = 25.4;
3049 0 : break;
3050 :
3051 0 : case 3: ImageInfo->FocalplaneUnits = 10; break; /* centimeter */
3052 0 : case 4: ImageInfo->FocalplaneUnits = 1; break; /* milimeter */
3053 0 : case 5: ImageInfo->FocalplaneUnits = .001; break; /* micrometer */
3054 : }
3055 0 : break;
3056 :
3057 : case TAG_SUB_IFD:
3058 0 : if (format==TAG_FMT_IFD) {
3059 : /* If this is called we are either in a TIFFs thumbnail or a JPEG where we cannot handle it */
3060 : /* TIFF thumbnail: our data structure cannot store a thumbnail of a thumbnail */
3061 : /* JPEG do we have the data area and what to do with it */
3062 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Skip SUB IFD");
3063 : }
3064 0 : break;
3065 :
3066 : case TAG_MAKE:
3067 17 : ImageInfo->make = estrdup(value_ptr);
3068 17 : break;
3069 : case TAG_MODEL:
3070 17 : ImageInfo->model = estrdup(value_ptr);
3071 17 : break;
3072 :
3073 : case TAG_MAKER_NOTE:
3074 0 : exif_process_IFD_in_MAKERNOTE(ImageInfo, value_ptr, byte_count, offset_base, IFDlength, displacement TSRMLS_CC);
3075 0 : break;
3076 :
3077 : case TAG_EXIF_IFD_POINTER:
3078 : case TAG_GPS_IFD_POINTER:
3079 : case TAG_INTEROP_IFD_POINTER:
3080 12 : if (ReadNextIFD) {
3081 : char *Subdir_start;
3082 12 : int sub_section_index = 0;
3083 12 : switch(tag) {
3084 : case TAG_EXIF_IFD_POINTER:
3085 : #ifdef EXIF_DEBUG
3086 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Found EXIF");
3087 : #endif
3088 6 : ImageInfo->sections_found |= FOUND_EXIF;
3089 6 : sub_section_index = SECTION_EXIF;
3090 6 : break;
3091 : case TAG_GPS_IFD_POINTER:
3092 : #ifdef EXIF_DEBUG
3093 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Found GPS");
3094 : #endif
3095 4 : ImageInfo->sections_found |= FOUND_GPS;
3096 4 : sub_section_index = SECTION_GPS;
3097 4 : break;
3098 : case TAG_INTEROP_IFD_POINTER:
3099 : #ifdef EXIF_DEBUG
3100 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Found INTEROPERABILITY");
3101 : #endif
3102 2 : ImageInfo->sections_found |= FOUND_INTEROP;
3103 2 : sub_section_index = SECTION_INTEROP;
3104 : break;
3105 : }
3106 12 : Subdir_start = offset_base + php_ifd_get32u(value_ptr, ImageInfo->motorola_intel);
3107 12 : if (Subdir_start < offset_base || Subdir_start > offset_base+IFDlength) {
3108 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD Pointer");
3109 0 : return FALSE;
3110 : }
3111 12 : if (!exif_process_IFD_in_JPEG(ImageInfo, Subdir_start, offset_base, IFDlength, displacement, sub_section_index TSRMLS_CC)) {
3112 0 : return FALSE;
3113 : }
3114 : #ifdef EXIF_DEBUG
3115 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Subsection %s done", exif_get_sectionname(sub_section_index));
3116 : #endif
3117 : }
3118 : }
3119 : }
3120 447 : exif_iif_add_tag(ImageInfo, section_index, exif_get_tagname(tag, tagname, sizeof(tagname), tag_table TSRMLS_CC), tag, format, components, value_ptr TSRMLS_CC);
3121 447 : EFREE_IF(outside);
3122 447 : return TRUE;
3123 : }
3124 : /* }}} */
3125 :
3126 : /* {{{ exif_process_IFD_in_JPEG
3127 : * Process one of the nested IFDs directories. */
3128 : static int exif_process_IFD_in_JPEG(image_info_type *ImageInfo, char *dir_start, char *offset_base, size_t IFDlength, size_t displacement, int section_index TSRMLS_DC)
3129 38 : {
3130 : int de;
3131 : int NumDirEntries;
3132 : int NextDirOffset;
3133 :
3134 : #ifdef EXIF_DEBUG
3135 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process %s (x%04X(=%d))", exif_get_sectionname(section_index), IFDlength, IFDlength);
3136 : #endif
3137 :
3138 38 : ImageInfo->sections_found |= FOUND_IFD0;
3139 :
3140 38 : NumDirEntries = php_ifd_get16u(dir_start, ImageInfo->motorola_intel);
3141 :
3142 38 : if ((dir_start+2+NumDirEntries*12) > (offset_base+IFDlength)) {
3143 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD size: x%04X + 2 + x%04X*12 = x%04X > x%04X", (int)((size_t)dir_start+2-(size_t)offset_base), NumDirEntries, (int)((size_t)dir_start+2+NumDirEntries*12-(size_t)offset_base), IFDlength);
3144 0 : return FALSE;
3145 : }
3146 :
3147 239 : for (de=0;de<NumDirEntries;de++) {
3148 201 : if (!exif_process_IFD_TAG(ImageInfo, dir_start + 2 + 12 * de,
3149 : offset_base, IFDlength, displacement, section_index, 1, exif_get_tag_table(section_index) TSRMLS_CC)) {
3150 0 : return FALSE;
3151 : }
3152 : }
3153 : /*
3154 : * Ignore IFD2 if it purportedly exists
3155 : */
3156 38 : if (section_index == SECTION_THUMBNAIL) {
3157 7 : return TRUE;
3158 : }
3159 : /*
3160 : * Hack to make it process IDF1 I hope
3161 : * There are 2 IDFs, the second one holds the keys (0x0201 and 0x0202) to the thumbnail
3162 : */
3163 31 : NextDirOffset = php_ifd_get32u(dir_start+2+12*de, ImageInfo->motorola_intel);
3164 31 : if (NextDirOffset) {
3165 : /* the next line seems false but here IFDlength means length of all IFDs */
3166 7 : if (offset_base + NextDirOffset < offset_base || offset_base + NextDirOffset > offset_base+IFDlength) {
3167 0 : exif_error_docref("exif_read_data#error_ifd" EXIFERR_CC, ImageInfo, E_WARNING, "Illegal IFD offset");
3168 0 : return FALSE;
3169 : }
3170 : /* That is the IFD for the first thumbnail */
3171 : #ifdef EXIF_DEBUG
3172 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Expect next IFD to be thumbnail");
3173 : #endif
3174 7 : if (exif_process_IFD_in_JPEG(ImageInfo, offset_base + NextDirOffset, offset_base, IFDlength, displacement, SECTION_THUMBNAIL TSRMLS_CC)) {
3175 : #ifdef EXIF_DEBUG
3176 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail size: 0x%04X", ImageInfo->Thumbnail.size);
3177 : #endif
3178 7 : if (ImageInfo->Thumbnail.filetype != IMAGE_FILETYPE_UNKNOWN
3179 : && ImageInfo->Thumbnail.size
3180 : && ImageInfo->Thumbnail.offset
3181 : && ImageInfo->read_thumbnail
3182 : ) {
3183 1 : exif_thumbnail_extract(ImageInfo, offset_base, IFDlength TSRMLS_CC);
3184 : }
3185 7 : return TRUE;
3186 : } else {
3187 0 : return FALSE;
3188 : }
3189 : }
3190 24 : return TRUE;
3191 : }
3192 : /* }}} */
3193 :
3194 : /* {{{ exif_process_TIFF_in_JPEG
3195 : Process a TIFF header in a JPEG file
3196 : */
3197 : static void exif_process_TIFF_in_JPEG(image_info_type *ImageInfo, char *CharBuf, size_t length, size_t displacement TSRMLS_DC)
3198 20 : {
3199 : unsigned exif_value_2a, offset_of_ifd;
3200 :
3201 : /* set the thumbnail stuff to nothing so we can test to see if they get set up */
3202 20 : if (memcmp(CharBuf, "II", 2) == 0) {
3203 8 : ImageInfo->motorola_intel = 0;
3204 12 : } else if (memcmp(CharBuf, "MM", 2) == 0) {
3205 12 : ImageInfo->motorola_intel = 1;
3206 : } else {
3207 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF alignment marker");
3208 0 : return;
3209 : }
3210 :
3211 : /* Check the next two values for correctness. */
3212 20 : exif_value_2a = php_ifd_get16u(CharBuf+2, ImageInfo->motorola_intel);
3213 20 : offset_of_ifd = php_ifd_get32u(CharBuf+4, ImageInfo->motorola_intel);
3214 20 : if ( exif_value_2a != 0x2a || offset_of_ifd < 0x08) {
3215 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF start (1)");
3216 0 : return;
3217 : }
3218 20 : if (offset_of_ifd > length) {
3219 1 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid IFD start");
3220 1 : return;
3221 : }
3222 :
3223 19 : ImageInfo->sections_found |= FOUND_IFD0;
3224 : /* First directory starts at offset 8. Offsets starts at 0. */
3225 19 : exif_process_IFD_in_JPEG(ImageInfo, CharBuf+offset_of_ifd, CharBuf, length/*-14*/, displacement, SECTION_IFD0 TSRMLS_CC);
3226 :
3227 : #ifdef EXIF_DEBUG
3228 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process TIFF in JPEG done");
3229 : #endif
3230 :
3231 : /* Compute the CCD width, in milimeters. */
3232 19 : if (ImageInfo->FocalplaneXRes != 0) {
3233 0 : ImageInfo->CCDWidth = (float)(ImageInfo->ExifImageWidth * ImageInfo->FocalplaneUnits / ImageInfo->FocalplaneXRes);
3234 : }
3235 : }
3236 : /* }}} */
3237 :
3238 : /* {{{ exif_process_APP1
3239 : Process an JPEG APP1 block marker
3240 : Describes all the drivel that most digital cameras include...
3241 : */
3242 : static void exif_process_APP1(image_info_type *ImageInfo, char *CharBuf, size_t length, size_t displacement TSRMLS_DC)
3243 20 : {
3244 : /* Check the APP1 for Exif Identifier Code */
3245 : static const uchar ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00};
3246 20 : if (length <= 8 || memcmp(CharBuf+2, ExifHeader, 6)) {
3247 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Incorrect APP1 Exif Identifier Code");
3248 0 : return;
3249 : }
3250 20 : exif_process_TIFF_in_JPEG(ImageInfo, CharBuf + 8, length - 8, displacement+8 TSRMLS_CC);
3251 : #ifdef EXIF_DEBUG
3252 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process APP1/EXIF done");
3253 : #endif
3254 : }
3255 : /* }}} */
3256 :
3257 : /* {{{ exif_process_APP12
3258 : Process an JPEG APP12 block marker used by OLYMPUS
3259 : */
3260 : static void exif_process_APP12(image_info_type *ImageInfo, char *buffer, size_t length TSRMLS_DC)
3261 0 : {
3262 0 : size_t l1, l2=0;
3263 :
3264 0 : if ((l1 = php_strnlen(buffer+2, length-2)) > 0) {
3265 0 : exif_iif_add_tag(ImageInfo, SECTION_APP12, "Company", TAG_NONE, TAG_FMT_STRING, l1, buffer+2 TSRMLS_CC);
3266 0 : if (length > 2+l1+1) {
3267 0 : l2 = php_strnlen(buffer+2+l1+1, length-2-l1+1);
3268 0 : exif_iif_add_tag(ImageInfo, SECTION_APP12, "Info", TAG_NONE, TAG_FMT_STRING, l2, buffer+2+l1+1 TSRMLS_CC);
3269 : }
3270 : }
3271 : #ifdef EXIF_DEBUG
3272 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process section APP12 with l1=%d, l2=%d done", l1, l2);
3273 : #endif
3274 0 : }
3275 : /* }}} */
3276 :
3277 : /* {{{ exif_scan_JPEG_header
3278 : * Parse the marker stream until SOS or EOI is seen; */
3279 : static int exif_scan_JPEG_header(image_info_type *ImageInfo TSRMLS_DC)
3280 21 : {
3281 : int section, sn;
3282 21 : int marker = 0, last_marker = M_PSEUDO, comment_correction=1;
3283 : unsigned int ll, lh;
3284 : uchar *Data;
3285 : size_t fpos, size, got, itemlen;
3286 : jpeg_sof_info sof_info;
3287 :
3288 195 : for(section=0;;section++) {
3289 : #ifdef EXIF_DEBUG
3290 : fpos = php_stream_tell(ImageInfo->infile);
3291 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Needing section %d @ 0x%08X", ImageInfo->file.count, fpos);
3292 : #endif
3293 :
3294 : /* get marker byte, swallowing possible padding */
3295 : /* some software does not count the length bytes of COM section */
3296 : /* one company doing so is very much envolved in JPEG... so we accept too */
3297 195 : if (last_marker==M_COM && comment_correction) {
3298 18 : comment_correction = 2;
3299 : }
3300 : do {
3301 389 : if ((marker = php_stream_getc(ImageInfo->infile)) == EOF) {
3302 0 : EXIF_ERRLOG_CORRUPT(ImageInfo)
3303 0 : return FALSE;
3304 : }
3305 389 : if (last_marker==M_COM && comment_correction>0) {
3306 18 : if (marker!=0xFF) {
3307 0 : marker = 0xff;
3308 0 : comment_correction--;
3309 : } else {
3310 18 : last_marker = M_PSEUDO; /* stop skipping 0 for M_COM */
3311 : }
3312 : }
3313 389 : } while (marker == 0xff);
3314 195 : if (last_marker==M_COM && !comment_correction) {
3315 0 : exif_error_docref("exif_read_data#error_mcom" EXIFERR_CC, ImageInfo, E_NOTICE, "Image has corrupt COM section: some software set wrong length information");
3316 : }
3317 195 : if (last_marker==M_COM && comment_correction)
3318 0 : return M_EOI; /* ah illegal: char after COM section not 0xFF */
3319 :
3320 195 : fpos = php_stream_tell(ImageInfo->infile);
3321 :
3322 195 : if (marker == 0xff) {
3323 : /* 0xff is legal padding, but if we get that many, something's wrong. */
3324 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "To many padding bytes");
3325 0 : return FALSE;
3326 : }
3327 :
3328 : /* Read the length of the section. */
3329 195 : if ((lh = php_stream_getc(ImageInfo->infile)) == EOF) {
3330 0 : EXIF_ERRLOG_CORRUPT(ImageInfo)
3331 0 : return FALSE;
3332 : }
3333 195 : if ((ll = php_stream_getc(ImageInfo->infile)) == EOF) {
3334 0 : EXIF_ERRLOG_CORRUPT(ImageInfo)
3335 0 : return FALSE;
3336 : }
3337 :
3338 195 : itemlen = (lh << 8) | ll;
3339 :
3340 195 : if (itemlen < 2) {
3341 : #ifdef EXIF_DEBUG
3342 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "%s, Section length: 0x%02X%02X", EXIF_ERROR_CORRUPT, lh, ll);
3343 : #else
3344 0 : EXIF_ERRLOG_CORRUPT(ImageInfo)
3345 : #endif
3346 0 : return FALSE;
3347 : }
3348 :
3349 195 : sn = exif_file_sections_add(ImageInfo, marker, itemlen+1, NULL);
3350 195 : Data = ImageInfo->file.list[sn].data;
3351 :
3352 : /* Store first two pre-read bytes. */
3353 195 : Data[0] = (uchar)lh;
3354 195 : Data[1] = (uchar)ll;
3355 :
3356 195 : got = php_stream_read(ImageInfo->infile, (char*)(Data+2), itemlen-2); /* Read the whole section. */
3357 195 : if (got != itemlen-2) {
3358 1 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error reading from file: got=x%04X(=%d) != itemlen-2=x%04X(=%d)", got, got, itemlen-2, itemlen-2);
3359 1 : return FALSE;
3360 : }
3361 :
3362 : #ifdef EXIF_DEBUG
3363 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Process section(x%02X=%s) @ x%04X + x%04X(=%d)", marker, exif_get_markername(marker), fpos, itemlen, itemlen);
3364 : #endif
3365 194 : switch(marker) {
3366 : case M_SOS: /* stop before hitting compressed data */
3367 : /* If reading entire image is requested, read the rest of the data. */
3368 20 : if (ImageInfo->read_all) {
3369 : /* Determine how much file is left. */
3370 0 : fpos = php_stream_tell(ImageInfo->infile);
3371 0 : size = ImageInfo->FileSize - fpos;
3372 0 : sn = exif_file_sections_add(ImageInfo, M_PSEUDO, size, NULL);
3373 0 : Data = ImageInfo->file.list[sn].data;
3374 0 : got = php_stream_read(ImageInfo->infile, (char*)Data, size);
3375 0 : if (got != size) {
3376 0 : EXIF_ERRLOG_FILEEOF(ImageInfo)
3377 0 : return FALSE;
3378 : }
3379 : }
3380 20 : return TRUE;
3381 :
3382 : case M_EOI: /* in case it's a tables-only JPEG stream */
3383 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "No image in jpeg!");
3384 0 : return (ImageInfo->sections_found&(~FOUND_COMPUTED)) ? TRUE : FALSE;
3385 :
3386 : case M_COM: /* Comment section */
3387 18 : exif_process_COM(ImageInfo, (char *)Data, itemlen TSRMLS_CC);
3388 18 : break;
3389 :
3390 : case M_EXIF:
3391 20 : if (!(ImageInfo->sections_found&FOUND_IFD0)) {
3392 : /*ImageInfo->sections_found |= FOUND_EXIF;*/
3393 : /* Seen files from some 'U-lead' software with Vivitar scanner
3394 : that uses marker 31 later in the file (no clue what for!) */
3395 20 : exif_process_APP1(ImageInfo, (char *)Data, itemlen, fpos TSRMLS_CC);
3396 : }
3397 20 : break;
3398 :
3399 : case M_APP12:
3400 0 : exif_process_APP12(ImageInfo, (char *)Data, itemlen TSRMLS_CC);
3401 0 : break;
3402 :
3403 :
3404 : case M_SOF0:
3405 : case M_SOF1:
3406 : case M_SOF2:
3407 : case M_SOF3:
3408 : case M_SOF5:
3409 : case M_SOF6:
3410 : case M_SOF7:
3411 : case M_SOF9:
3412 : case M_SOF10:
3413 : case M_SOF11:
3414 : case M_SOF13:
3415 : case M_SOF14:
3416 : case M_SOF15:
3417 20 : exif_process_SOFn(Data, marker, &sof_info);
3418 20 : ImageInfo->Width = sof_info.width;
3419 20 : ImageInfo->Height = sof_info.height;
3420 20 : if (sof_info.num_components == 3) {
3421 20 : ImageInfo->IsColor = 1;
3422 : } else {
3423 0 : ImageInfo->IsColor = 0;
3424 : }
3425 : break;
3426 : default:
3427 : /* skip any other marker silently. */
3428 : break;
3429 : }
3430 :
3431 : /* keep track of last marker */
3432 174 : last_marker = marker;
3433 174 : }
3434 : #ifdef EXIF_DEBUG
3435 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Done");
3436 : #endif
3437 : return TRUE;
3438 : }
3439 : /* }}} */
3440 :
3441 : /* {{{ exif_scan_thumbnail
3442 : * scan JPEG in thumbnail (memory) */
3443 : static int exif_scan_thumbnail(image_info_type *ImageInfo TSRMLS_DC)
3444 5 : {
3445 5 : uchar c, *data = (uchar*)ImageInfo->Thumbnail.data;
3446 : int n, marker;
3447 5 : size_t length=2, pos=0;
3448 : jpeg_sof_info sof_info;
3449 :
3450 5 : if (!data) {
3451 5 : return FALSE; /* nothing to do here */
3452 : }
3453 0 : if (memcmp(data, "\xFF\xD8\xFF", 3)) {
3454 0 : if (!ImageInfo->Thumbnail.width && !ImageInfo->Thumbnail.height) {
3455 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Thumbnail is not a JPEG image");
3456 : }
3457 0 : return FALSE;
3458 : }
3459 : for (;;) {
3460 0 : pos += length;
3461 0 : if (pos>=ImageInfo->Thumbnail.size)
3462 0 : return FALSE;
3463 0 : c = data[pos++];
3464 0 : if (pos>=ImageInfo->Thumbnail.size)
3465 0 : return FALSE;
3466 0 : if (c != 0xFF) {
3467 0 : return FALSE;
3468 : }
3469 0 : n = 8;
3470 0 : while ((c = data[pos++]) == 0xFF && n--) {
3471 0 : if (pos+3>=ImageInfo->Thumbnail.size)
3472 0 : return FALSE;
3473 : /* +3 = pos++ of next check when reaching marker + 2 bytes for length */
3474 : }
3475 0 : if (c == 0xFF)
3476 0 : return FALSE;
3477 0 : marker = c;
3478 0 : length = php_jpg_get16(data+pos);
3479 0 : if (pos+length>=ImageInfo->Thumbnail.size) {
3480 0 : return FALSE;
3481 : }
3482 : #ifdef EXIF_DEBUG
3483 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: process section(x%02X=%s) @ x%04X + x%04X", marker, exif_get_markername(marker), pos, length);
3484 : #endif
3485 0 : switch (marker) {
3486 : case M_SOF0:
3487 : case M_SOF1:
3488 : case M_SOF2:
3489 : case M_SOF3:
3490 : case M_SOF5:
3491 : case M_SOF6:
3492 : case M_SOF7:
3493 : case M_SOF9:
3494 : case M_SOF10:
3495 : case M_SOF11:
3496 : case M_SOF13:
3497 : case M_SOF14:
3498 : case M_SOF15:
3499 : /* handle SOFn block */
3500 0 : exif_process_SOFn(data+pos, marker, &sof_info);
3501 0 : ImageInfo->Thumbnail.height = sof_info.height;
3502 0 : ImageInfo->Thumbnail.width = sof_info.width;
3503 : #ifdef EXIF_DEBUG
3504 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Thumbnail: size: %d * %d", sof_info.width, sof_info.height);
3505 : #endif
3506 0 : return TRUE;
3507 :
3508 : case M_SOS:
3509 : case M_EOI:
3510 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Could not compute size of thumbnail");
3511 0 : return FALSE;
3512 : break;
3513 :
3514 : default:
3515 : /* just skip */
3516 : break;
3517 : }
3518 0 : }
3519 :
3520 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Could not compute size of thumbnail");
3521 : return FALSE;
3522 : }
3523 : /* }}} */
3524 :
3525 : /* {{{ exif_process_IFD_in_TIFF
3526 : * Parse the TIFF header; */
3527 : static int exif_process_IFD_in_TIFF(image_info_type *ImageInfo, size_t dir_offset, int section_index TSRMLS_DC)
3528 20 : {
3529 20 : int i, sn, num_entries, sub_section_index = 0;
3530 : unsigned char *dir_entry;
3531 : char tagname[64];
3532 20 : size_t ifd_size, dir_size, entry_offset, next_offset, entry_length, entry_value=0, fgot;
3533 : int entry_tag , entry_type;
3534 20 : tag_table_type tag_table = exif_get_tag_table(section_index);
3535 :
3536 20 : if (ImageInfo->ifd_nesting_level > MAX_IFD_NESTING_LEVEL) {
3537 0 : return FALSE;
3538 : }
3539 :
3540 20 : if (ImageInfo->FileSize >= dir_offset+2) {
3541 20 : sn = exif_file_sections_add(ImageInfo, M_PSEUDO, 2, NULL);
3542 : #ifdef EXIF_DEBUG
3543 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, 2);
3544 : #endif
3545 20 : php_stream_seek(ImageInfo->infile, dir_offset, SEEK_SET); /* we do not know the order of sections */
3546 20 : php_stream_read(ImageInfo->infile, (char*)ImageInfo->file.list[sn].data, 2);
3547 20 : num_entries = php_ifd_get16u(ImageInfo->file.list[sn].data, ImageInfo->motorola_intel);
3548 20 : dir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/;
3549 20 : if (ImageInfo->FileSize >= dir_offset+dir_size) {
3550 : #ifdef EXIF_DEBUG
3551 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: filesize(x%04X), IFD dir(x%04X + x%04X), IFD entries(%d)", ImageInfo->FileSize, dir_offset+2, dir_size-2, num_entries);
3552 : #endif
3553 20 : if (exif_file_sections_realloc(ImageInfo, sn, dir_size TSRMLS_CC)) {
3554 0 : return FALSE;
3555 : }
3556 20 : php_stream_read(ImageInfo->infile, (char*)(ImageInfo->file.list[sn].data+2), dir_size-2);
3557 : /*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Dump: %s", exif_char_dump(ImageInfo->file.list[sn].data, dir_size, 0));*/
3558 20 : next_offset = php_ifd_get32u(ImageInfo->file.list[sn].data + dir_size - 4, ImageInfo->motorola_intel);
3559 : #ifdef EXIF_DEBUG
3560 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF done, next offset x%04X", next_offset);
3561 : #endif
3562 : /* now we have the directory we can look how long it should be */
3563 20 : ifd_size = dir_size;
3564 277 : for(i=0;i<num_entries;i++) {
3565 257 : dir_entry = ImageInfo->file.list[sn].data+2+i*12;
3566 257 : entry_tag = php_ifd_get16u(dir_entry+0, ImageInfo->motorola_intel);
3567 257 : entry_type = php_ifd_get16u(dir_entry+2, ImageInfo->motorola_intel);
3568 257 : if (entry_type > NUM_FORMATS) {
3569 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: tag(0x%04X,%12s): Illegal format code 0x%04X, switching to BYTE", entry_tag, exif_get_tagname(entry_tag, tagname, -12, tag_table TSRMLS_CC), entry_type);
3570 : /* Since this is repeated in exif_process_IFD_TAG make it a notice here */
3571 : /* and make it a warning in the exif_process_IFD_TAG which is called */
3572 : /* elsewhere. */
3573 0 : entry_type = TAG_FMT_BYTE;
3574 : /*The next line would break the image on writeback: */
3575 : /* php_ifd_set16u(dir_entry+2, entry_type, ImageInfo->motorola_intel);*/
3576 : }
3577 257 : entry_length = php_ifd_get32u(dir_entry+4, ImageInfo->motorola_intel) * php_tiff_bytes_per_format[entry_type];
3578 257 : if (entry_length <= 4) {
3579 152 : switch(entry_type) {
3580 : case TAG_FMT_USHORT:
3581 99 : entry_value = php_ifd_get16u(dir_entry+8, ImageInfo->motorola_intel);
3582 99 : break;
3583 : case TAG_FMT_SSHORT:
3584 0 : entry_value = php_ifd_get16s(dir_entry+8, ImageInfo->motorola_intel);
3585 0 : break;
3586 : case TAG_FMT_ULONG:
3587 33 : entry_value = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel);
3588 33 : break;
3589 : case TAG_FMT_SLONG:
3590 0 : entry_value = php_ifd_get32s(dir_entry+8, ImageInfo->motorola_intel);
3591 : break;
3592 : }
3593 152 : switch(entry_tag) {
3594 : case TAG_IMAGEWIDTH:
3595 : case TAG_COMP_IMAGE_WIDTH:
3596 12 : ImageInfo->Width = entry_value;
3597 12 : break;
3598 : case TAG_IMAGEHEIGHT:
3599 : case TAG_COMP_IMAGE_HEIGHT:
3600 12 : ImageInfo->Height = entry_value;
3601 12 : break;
3602 : case TAG_PHOTOMETRIC_INTERPRETATION:
3603 9 : switch (entry_value) {
3604 : case PMI_BLACK_IS_ZERO:
3605 : case PMI_WHITE_IS_ZERO:
3606 : case PMI_TRANSPARENCY_MASK:
3607 0 : ImageInfo->IsColor = 0;
3608 0 : break;
3609 : case PMI_RGB:
3610 : case PMI_PALETTE_COLOR:
3611 : case PMI_SEPARATED:
3612 : case PMI_YCBCR:
3613 : case PMI_CIELAB:
3614 9 : ImageInfo->IsColor = 1;
3615 : break;
3616 : }
3617 : break;
3618 : }
3619 : } else {
3620 105 : entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel);
3621 : /* if entry needs expading ifd cache and entry is at end of current ifd cache. */
3622 : /* otherwise there may be huge holes between two entries */
3623 105 : if (entry_offset + entry_length > dir_offset + ifd_size
3624 : && entry_offset == dir_offset + ifd_size) {
3625 60 : ifd_size = entry_offset + entry_length - dir_offset;
3626 : #ifdef EXIF_DEBUG
3627 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Resize struct: x%04X + x%04X - x%04X = x%04X", entry_offset, entry_length, dir_offset, ifd_size);
3628 : #endif
3629 : }
3630 : }
3631 : }
3632 20 : if (ImageInfo->FileSize >= dir_offset + ImageInfo->file.list[sn].size) {
3633 20 : if (ifd_size > dir_size) {
3634 18 : if (dir_offset + ifd_size > ImageInfo->FileSize) {
3635 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error in TIFF: filesize(x%04X) less than size of IFD(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, ifd_size);
3636 0 : return FALSE;
3637 : }
3638 18 : if (exif_file_sections_realloc(ImageInfo, sn, ifd_size TSRMLS_CC)) {
3639 0 : return FALSE;
3640 : }
3641 : /* read values not stored in directory itself */
3642 : #ifdef EXIF_DEBUG
3643 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF: filesize(x%04X), IFD(x%04X + x%04X)", ImageInfo->FileSize, dir_offset, ifd_size);
3644 : #endif
3645 18 : php_stream_read(ImageInfo->infile, (char*)(ImageInfo->file.list[sn].data+dir_size), ifd_size-dir_size);
3646 : #ifdef EXIF_DEBUG
3647 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read from TIFF, done");
3648 : #endif
3649 : }
3650 : /* now process the tags */
3651 277 : for(i=0;i<num_entries;i++) {
3652 257 : dir_entry = ImageInfo->file.list[sn].data+2+i*12;
3653 257 : entry_tag = php_ifd_get16u(dir_entry+0, ImageInfo->motorola_intel);
3654 257 : entry_type = php_ifd_get16u(dir_entry+2, ImageInfo->motorola_intel);
3655 : /*entry_length = php_ifd_get32u(dir_entry+4, ImageInfo->motorola_intel);*/
3656 268 : if (entry_tag == TAG_EXIF_IFD_POINTER ||
3657 : entry_tag == TAG_INTEROP_IFD_POINTER ||
3658 : entry_tag == TAG_GPS_IFD_POINTER ||
3659 : entry_tag == TAG_SUB_IFD
3660 : ) {
3661 11 : switch(entry_tag) {
3662 : case TAG_EXIF_IFD_POINTER:
3663 5 : ImageInfo->sections_found |= FOUND_EXIF;
3664 5 : sub_section_index = SECTION_EXIF;
3665 5 : break;
3666 : case TAG_GPS_IFD_POINTER:
3667 4 : ImageInfo->sections_found |= FOUND_GPS;
3668 4 : sub_section_index = SECTION_GPS;
3669 4 : break;
3670 : case TAG_INTEROP_IFD_POINTER:
3671 2 : ImageInfo->sections_found |= FOUND_INTEROP;
3672 2 : sub_section_index = SECTION_INTEROP;
3673 2 : break;
3674 : case TAG_SUB_IFD:
3675 0 : ImageInfo->sections_found |= FOUND_THUMBNAIL;
3676 0 : sub_section_index = SECTION_THUMBNAIL;
3677 : break;
3678 : }
3679 11 : entry_offset = php_ifd_get32u(dir_entry+8, ImageInfo->motorola_intel);
3680 : #ifdef EXIF_DEBUG
3681 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Next IFD: %s @x%04X", exif_get_sectionname(sub_section_index), entry_offset);
3682 : #endif
3683 11 : ImageInfo->ifd_nesting_level++;
3684 11 : exif_process_IFD_in_TIFF(ImageInfo, entry_offset, sub_section_index TSRMLS_CC);
3685 11 : if (section_index!=SECTION_THUMBNAIL && entry_tag==TAG_SUB_IFD) {
3686 0 : if (ImageInfo->Thumbnail.filetype != IMAGE_FILETYPE_UNKNOWN
3687 : && ImageInfo->Thumbnail.size
3688 : && ImageInfo->Thumbnail.offset
3689 : && ImageInfo->read_thumbnail
3690 : ) {
3691 : #ifdef EXIF_DEBUG
3692 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "%s THUMBNAIL @0x%04X + 0x%04X", ImageInfo->Thumbnail.data ? "Ignore" : "Read", ImageInfo->Thumbnail.offset, ImageInfo->Thumbnail.size);
3693 : #endif
3694 0 : if (!ImageInfo->Thumbnail.data) {
3695 0 : ImageInfo->Thumbnail.data = safe_emalloc(ImageInfo->Thumbnail.size, 1, 0);
3696 0 : php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
3697 0 : fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
3698 0 : if (fgot < ImageInfo->Thumbnail.size) {
3699 0 : EXIF_ERRLOG_THUMBEOF(ImageInfo)
3700 : }
3701 0 : exif_thumbnail_build(ImageInfo TSRMLS_CC);
3702 : }
3703 : }
3704 : }
3705 : #ifdef EXIF_DEBUG
3706 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Next IFD: %s done", exif_get_sectionname(sub_section_index));
3707 : #endif
3708 : } else {
3709 246 : if (!exif_process_IFD_TAG(ImageInfo, (char*)dir_entry,
3710 : (char*)(ImageInfo->file.list[sn].data-dir_offset),
3711 : ifd_size, 0, section_index, 0, tag_table TSRMLS_CC)) {
3712 0 : return FALSE;
3713 : }
3714 : }
3715 : }
3716 : /* If we had a thumbnail in a SUB_IFD we have ANOTHER image in NEXT IFD */
3717 20 : if (next_offset && section_index != SECTION_THUMBNAIL) {
3718 : /* this should be a thumbnail IFD */
3719 : /* the thumbnail itself is stored at Tag=StripOffsets */
3720 : #ifdef EXIF_DEBUG
3721 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read next IFD (THUMBNAIL) at x%04X", next_offset);
3722 : #endif
3723 0 : ImageInfo->ifd_nesting_level++;
3724 0 : exif_process_IFD_in_TIFF(ImageInfo, next_offset, SECTION_THUMBNAIL TSRMLS_CC);
3725 : #ifdef EXIF_DEBUG
3726 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "%s THUMBNAIL @0x%04X + 0x%04X", ImageInfo->Thumbnail.data ? "Ignore" : "Read", ImageInfo->Thumbnail.offset, ImageInfo->Thumbnail.size);
3727 : #endif
3728 0 : if (!ImageInfo->Thumbnail.data && ImageInfo->Thumbnail.offset && ImageInfo->Thumbnail.size && ImageInfo->read_thumbnail) {
3729 0 : ImageInfo->Thumbnail.data = safe_emalloc(ImageInfo->Thumbnail.size, 1, 0);
3730 0 : php_stream_seek(ImageInfo->infile, ImageInfo->Thumbnail.offset, SEEK_SET);
3731 0 : fgot = php_stream_read(ImageInfo->infile, ImageInfo->Thumbnail.data, ImageInfo->Thumbnail.size);
3732 0 : if (fgot < ImageInfo->Thumbnail.size) {
3733 0 : EXIF_ERRLOG_THUMBEOF(ImageInfo)
3734 : }
3735 0 : exif_thumbnail_build(ImageInfo TSRMLS_CC);
3736 : }
3737 : #ifdef EXIF_DEBUG
3738 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Read next IFD (THUMBNAIL) done");
3739 : #endif
3740 : }
3741 20 : return TRUE;
3742 : } else {
3743 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error in TIFF: filesize(x%04X) less than size of IFD(x%04X)", ImageInfo->FileSize, dir_offset+ImageInfo->file.list[sn].size);
3744 0 : return FALSE;
3745 : }
3746 : } else {
3747 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error in TIFF: filesize(x%04X) less than size of IFD dir(x%04X)", ImageInfo->FileSize, dir_offset+dir_size);
3748 0 : return FALSE;
3749 : }
3750 : } else {
3751 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Error in TIFF: filesize(x%04X) less than start of IFD dir(x%04X)", ImageInfo->FileSize, dir_offset+2);
3752 0 : return FALSE;
3753 : }
3754 : }
3755 : /* }}} */
3756 :
3757 : /* {{{ exif_scan_FILE_header
3758 : * Parse the marker stream until SOS or EOI is seen; */
3759 : static int exif_scan_FILE_header(image_info_type *ImageInfo TSRMLS_DC)
3760 30 : {
3761 : unsigned char file_header[8];
3762 30 : int ret = FALSE;
3763 :
3764 30 : ImageInfo->FileType = IMAGE_FILETYPE_UNKNOWN;
3765 :
3766 30 : if (ImageInfo->FileSize >= 2) {
3767 30 : php_stream_seek(ImageInfo->infile, 0, SEEK_SET);
3768 30 : if (php_stream_read(ImageInfo->infile, (char*)file_header, 2) != 2) {
3769 0 : return FALSE;
3770 : }
3771 51 : if ((file_header[0]==0xff) && (file_header[1]==M_SOI)) {
3772 21 : ImageInfo->FileType = IMAGE_FILETYPE_JPEG;
3773 21 : if (exif_scan_JPEG_header(ImageInfo TSRMLS_CC)) {
3774 20 : ret = TRUE;
3775 : } else {
3776 1 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid JPEG file");
3777 : }
3778 9 : } else if (ImageInfo->FileSize >= 8) {
3779 9 : if (php_stream_read(ImageInfo->infile, (char*)(file_header+2), 6) != 6) {
3780 0 : return FALSE;
3781 : }
3782 9 : if (!memcmp(file_header, "II\x2A\x00", 4)) {
3783 5 : ImageInfo->FileType = IMAGE_FILETYPE_TIFF_II;
3784 5 : ImageInfo->motorola_intel = 0;
3785 : #ifdef EXIF_DEBUG
3786 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/II format");
3787 : #endif
3788 5 : ImageInfo->sections_found |= FOUND_IFD0;
3789 5 : if (exif_process_IFD_in_TIFF(ImageInfo,
3790 : php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel),
3791 : SECTION_IFD0 TSRMLS_CC)) {
3792 5 : ret = TRUE;
3793 : } else {
3794 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file");
3795 : }
3796 4 : } else if (!memcmp(file_header, "MM\x00\x2a", 4)) {
3797 4 : ImageInfo->FileType = IMAGE_FILETYPE_TIFF_MM;
3798 4 : ImageInfo->motorola_intel = 1;
3799 : #ifdef EXIF_DEBUG
3800 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "File has TIFF/MM format");
3801 : #endif
3802 4 : ImageInfo->sections_found |= FOUND_IFD0;
3803 4 : if (exif_process_IFD_in_TIFF(ImageInfo,
3804 : php_ifd_get32u(file_header + 4, ImageInfo->motorola_intel),
3805 : SECTION_IFD0 TSRMLS_CC)) {
3806 4 : ret = TRUE;
3807 : } else {
3808 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Invalid TIFF file");
3809 : }
3810 : } else {
3811 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File not supported");
3812 0 : return FALSE;
3813 : }
3814 : }
3815 : } else {
3816 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "File too small (%d)", ImageInfo->FileSize);
3817 : }
3818 30 : return ret;
3819 : }
3820 : /* }}} */
3821 :
3822 : /* {{{ exif_discard_imageinfo
3823 : Discard data scanned by exif_read_file.
3824 : */
3825 : static int exif_discard_imageinfo(image_info_type *ImageInfo)
3826 30 : {
3827 : int i;
3828 :
3829 30 : EFREE_IF(ImageInfo->FileName);
3830 30 : EFREE_IF(ImageInfo->UserComment);
3831 30 : EFREE_IF(ImageInfo->UserCommentEncoding);
3832 30 : EFREE_IF(ImageInfo->Copyright);
3833 30 : EFREE_IF(ImageInfo->CopyrightPhotographer);
3834 30 : EFREE_IF(ImageInfo->CopyrightEditor);
3835 30 : EFREE_IF(ImageInfo->Thumbnail.data);
3836 30 : EFREE_IF(ImageInfo->encode_unicode);
3837 30 : EFREE_IF(ImageInfo->decode_unicode_be);
3838 30 : EFREE_IF(ImageInfo->decode_unicode_le);
3839 30 : EFREE_IF(ImageInfo->encode_jis);
3840 30 : EFREE_IF(ImageInfo->decode_jis_be);
3841 30 : EFREE_IF(ImageInfo->decode_jis_le);
3842 30 : EFREE_IF(ImageInfo->make);
3843 30 : EFREE_IF(ImageInfo->model);
3844 35 : for (i=0; i<ImageInfo->xp_fields.count; i++) {
3845 5 : EFREE_IF(ImageInfo->xp_fields.list[i].value);
3846 : }
3847 30 : EFREE_IF(ImageInfo->xp_fields.list);
3848 450 : for (i=0; i<SECTION_COUNT; i++) {
3849 420 : exif_iif_free(ImageInfo, i);
3850 : }
3851 30 : exif_file_sections_free(ImageInfo);
3852 30 : memset(ImageInfo, 0, sizeof(*ImageInfo));
3853 30 : return TRUE;
3854 : }
3855 : /* }}} */
3856 :
3857 : /* {{{ exif_read_file
3858 : */
3859 : static int exif_read_file(image_info_type *ImageInfo, char *FileName, int read_thumbnail, int read_all TSRMLS_DC)
3860 30 : {
3861 : int ret;
3862 : struct stat st;
3863 :
3864 : /* Start with an empty image information structure. */
3865 30 : memset(ImageInfo, 0, sizeof(*ImageInfo));
3866 :
3867 30 : ImageInfo->motorola_intel = -1; /* flag as unknown */
3868 :
3869 30 : ImageInfo->infile = php_stream_open_wrapper(FileName, "rb", STREAM_MUST_SEEK|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
3870 30 : if (!ImageInfo->infile) {
3871 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Unable to open file");
3872 0 : return FALSE;
3873 : }
3874 :
3875 30 : if (php_stream_is(ImageInfo->infile, PHP_STREAM_IS_STDIO)) {
3876 30 : if (VCWD_STAT(FileName, &st) >= 0) {
3877 30 : if ((st.st_mode & S_IFMT) != S_IFREG) {
3878 0 : exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_WARNING, "Not a file");
3879 0 : php_stream_close(ImageInfo->infile);
3880 0 : return FALSE;
3881 : }
3882 :
3883 : /* Store file date/time. */
3884 30 : ImageInfo->FileDateTime = st.st_mtime;
3885 30 : ImageInfo->FileSize = st.st_size;
3886 : /*exif_error_docref(NULL EXIFERR_CC, ImageInfo, E_NOTICE, "Opened stream is file: %d", ImageInfo->FileSize);*/
3887 : }
3888 : } else {
3889 0 : if (!ImageInfo->FileSize) {
3890 0 : php_stream_seek(ImageInfo->infile, 0, SEEK_END);
3891 0 : ImageInfo->FileSize = php_stream_tell(ImageInfo->infile);
3892 0 : php_stream_seek(ImageInfo->infile, 0, SEEK_SET);
3893 : }
3894 : }
3895 :
3896 30 : php_basename(FileName, strlen(FileName), NULL, 0, &(ImageInfo->FileName), NULL TSRMLS_CC);
3897 30 : ImageInfo->read_thumbnail = read_thumbnail;
3898 30 : ImageInfo->read_all = read_all;
3899 30 : ImageInfo->Thumbnail.filetype = IMAGE_FILETYPE_UNKNOWN;
3900 :
3901 30 : ImageInfo->encode_unicode = safe_estrdup(EXIF_G(encode_unicode));
3902 30 : ImageInfo->decode_unicode_be = safe_estrdup(EXIF_G(decode_unicode_be));
3903 30 : ImageInfo->decode_unicode_le = safe_estrdup(EXIF_G(decode_unicode_le));
3904 30 : ImageInfo->encode_jis = safe_estrdup(EXIF_G(encode_jis));
3905 30 : ImageInfo->decode_jis_be = safe_estrdup(EXIF_G(decode_jis_be));
3906 30 : ImageInfo->decode_jis_le = safe_estrdup(EXIF_G(decode_jis_le));
3907 :
3908 :
3909 30 : ImageInfo->ifd_nesting_level = 0;
3910 :
3911 : /* Scan the JPEG headers. */
3912 30 : ret = exif_scan_FILE_header(ImageInfo TSRMLS_CC);
3913 :
3914 30 : php_stream_close(ImageInfo->infile);
3915 30 : return ret;
3916 : }
3917 : /* }}} */
3918 :
3919 : /* {{{ proto array exif_read_data(string filename [, sections_needed [, sub_arrays[, read_thumbnail]]])
3920 : Reads header data from the JPEG/TIFF image filename and optionally reads the internal thumbnails */
3921 : PHP_FUNCTION(exif_read_data)
3922 29 : {
3923 : zval **p_name, **p_sections_needed, **p_sub_arrays, **p_read_thumbnail, **p_read_all;
3924 29 : int i, ac = ZEND_NUM_ARGS(), ret, sections_needed=0, sub_arrays=0, read_thumbnail=0, read_all=0;
3925 : image_info_type ImageInfo;
3926 : char tmp[64], *sections_str, *s;
3927 :
3928 29 : memset(&ImageInfo, 0, sizeof(ImageInfo));
3929 :
3930 29 : if ((ac < 1 || ac > 4) || zend_get_parameters_ex(ac, &p_name, &p_sections_needed, &p_sub_arrays, &p_read_thumbnail, &p_read_all) == FAILURE) {
3931 0 : WRONG_PARAM_COUNT;
3932 : }
3933 :
3934 29 : convert_to_string_ex(p_name);
3935 :
3936 29 : if(ac >= 2) {
3937 6 : convert_to_string_ex(p_sections_needed);
3938 6 : spprintf(§ions_str, 0, ",%s,", Z_STRVAL_PP(p_sections_needed));
3939 : /* sections_str DOES start with , and SPACES are NOT allowed in names */
3940 6 : s = sections_str;
3941 39 : while(*++s) {
3942 27 : if(*s==' ') {
3943 0 : *s = ',';
3944 : }
3945 : }
3946 90 : for (i=0; i<SECTION_COUNT; i++) {
3947 84 : snprintf(tmp, sizeof(tmp), ",%s,", exif_get_sectionname(i));
3948 84 : if (strstr(sections_str, tmp)) {
3949 3 : sections_needed |= 1<<i;
3950 : }
3951 : }
3952 6 : EFREE_IF(sections_str);
3953 : /* now see what we need */
3954 : #ifdef EXIF_DEBUG
3955 : sections_str = exif_get_sectionlist(sections_needed TSRMLS_CC);
3956 : if (!sections_str) {
3957 : RETURN_FALSE;
3958 : }
3959 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Sections needed: %s", sections_str[0] ? sections_str : "None");
3960 : EFREE_IF(sections_str);
3961 : #endif
3962 : }
3963 29 : if(ac >= 3) {
3964 5 : convert_to_long_ex(p_sub_arrays);
3965 5 : sub_arrays = Z_LVAL_PP(p_sub_arrays);
3966 : }
3967 29 : if(ac >= 4) {
3968 5 : convert_to_long_ex(p_read_thumbnail);
3969 5 : read_thumbnail = Z_LVAL_PP(p_read_thumbnail);
3970 : }
3971 29 : if(ac >= 5) {
3972 0 : convert_to_long_ex(p_read_all);
3973 0 : read_all = Z_LVAL_PP(p_read_all);
3974 : }
3975 : /* parameters 3,4 will be working in later versions.... */
3976 29 : read_all = 0; /* just to make function work for 4.2 tree */
3977 :
3978 29 : ret = exif_read_file(&ImageInfo, Z_STRVAL_PP(p_name), read_thumbnail, read_all TSRMLS_CC);
3979 :
3980 29 : sections_str = exif_get_sectionlist(ImageInfo.sections_found TSRMLS_CC);
3981 :
3982 : #ifdef EXIF_DEBUG
3983 : if (sections_str)
3984 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Sections found: %s", sections_str[0] ? sections_str : "None");
3985 : #endif
3986 :
3987 29 : ImageInfo.sections_found |= FOUND_COMPUTED|FOUND_FILE;/* do not inform about in debug*/
3988 :
3989 29 : if (ret==FALSE || (sections_needed && !(sections_needed&ImageInfo.sections_found))) {
3990 : /* array_init must be checked at last! otherwise the array must be freed if a later test fails. */
3991 1 : exif_discard_imageinfo(&ImageInfo);
3992 1 : EFREE_IF(sections_str);
3993 1 : RETURN_FALSE;
3994 : }
3995 :
3996 28 : array_init(return_value);
3997 :
3998 : #ifdef EXIF_DEBUG
3999 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Generate section FILE");
4000 : #endif
4001 :
4002 : /* now we can add our information */
4003 28 : exif_iif_add_str(&ImageInfo, SECTION_FILE, "FileName", ImageInfo.FileName TSRMLS_CC);
4004 28 : exif_iif_add_int(&ImageInfo, SECTION_FILE, "FileDateTime", ImageInfo.FileDateTime TSRMLS_CC);
4005 28 : exif_iif_add_int(&ImageInfo, SECTION_FILE, "FileSize", ImageInfo.FileSize TSRMLS_CC);
4006 28 : exif_iif_add_int(&ImageInfo, SECTION_FILE, "FileType", ImageInfo.FileType TSRMLS_CC);
4007 28 : exif_iif_add_str(&ImageInfo, SECTION_FILE, "MimeType", (char*)php_image_type_to_mime_type(ImageInfo.FileType) TSRMLS_CC);
4008 28 : exif_iif_add_str(&ImageInfo, SECTION_FILE, "SectionsFound", sections_str ? sections_str : "NONE" TSRMLS_CC);
4009 :
4010 : #ifdef EXIF_DEBUG
4011 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Generate section COMPUTED");
4012 : #endif
4013 :
4014 28 : if (ImageInfo.Width>0 && ImageInfo.Height>0) {
4015 28 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "html" TSRMLS_CC, "width=\"%d\" height=\"%d\"", ImageInfo.Width, ImageInfo.Height);
4016 28 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Height", ImageInfo.Height TSRMLS_CC);
4017 28 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Width", ImageInfo.Width TSRMLS_CC);
4018 : }
4019 28 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "IsColor", ImageInfo.IsColor TSRMLS_CC);
4020 28 : if (ImageInfo.motorola_intel != -1) {
4021 27 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "ByteOrderMotorola", ImageInfo.motorola_intel TSRMLS_CC);
4022 : }
4023 28 : if (ImageInfo.FocalLength) {
4024 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "FocalLength" TSRMLS_CC, "%4.1Fmm", ImageInfo.FocalLength);
4025 0 : if(ImageInfo.CCDWidth) {
4026 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "35mmFocalLength" TSRMLS_CC, "%dmm", (int)(ImageInfo.FocalLength/ImageInfo.CCDWidth*35+0.5));
4027 : }
4028 : }
4029 28 : if(ImageInfo.CCDWidth) {
4030 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "CCDWidth" TSRMLS_CC, "%dmm", (int)ImageInfo.CCDWidth);
4031 : }
4032 28 : if(ImageInfo.ExposureTime>0) {
4033 0 : if(ImageInfo.ExposureTime <= 0.5) {
4034 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ExposureTime" TSRMLS_CC, "%0.3F s (1/%d)", ImageInfo.ExposureTime, (int)(0.5 + 1/ImageInfo.ExposureTime));
4035 : } else {
4036 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ExposureTime" TSRMLS_CC, "%0.3F s", ImageInfo.ExposureTime);
4037 : }
4038 : }
4039 28 : if(ImageInfo.ApertureFNumber) {
4040 7 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ApertureFNumber" TSRMLS_CC, "f/%.1F", ImageInfo.ApertureFNumber);
4041 : }
4042 28 : if(ImageInfo.Distance) {
4043 0 : if(ImageInfo.Distance<0) {
4044 0 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "FocusDistance", "Infinite" TSRMLS_CC);
4045 : } else {
4046 0 : exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "FocusDistance" TSRMLS_CC, "%0.2Fm", ImageInfo.Distance);
4047 : }
4048 : }
4049 28 : if (ImageInfo.UserComment) {
4050 5 : exif_iif_add_buffer(&ImageInfo, SECTION_COMPUTED, "UserComment", ImageInfo.UserCommentLength, ImageInfo.UserComment TSRMLS_CC);
4051 5 : if (ImageInfo.UserCommentEncoding && strlen(ImageInfo.UserCommentEncoding)) {
4052 5 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "UserCommentEncoding", ImageInfo.UserCommentEncoding TSRMLS_CC);
4053 : }
4054 : }
4055 :
4056 28 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "Copyright", ImageInfo.Copyright TSRMLS_CC);
4057 28 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "Copyright.Photographer", ImageInfo.CopyrightPhotographer TSRMLS_CC);
4058 28 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "Copyright.Editor", ImageInfo.CopyrightEditor TSRMLS_CC);
4059 :
4060 33 : for (i=0; i<ImageInfo.xp_fields.count; i++) {
4061 5 : exif_iif_add_str(&ImageInfo, SECTION_WINXP, exif_get_tagname(ImageInfo.xp_fields.list[i].tag, NULL, 0, exif_get_tag_table(SECTION_WINXP) TSRMLS_CC), ImageInfo.xp_fields.list[i].value TSRMLS_CC);
4062 : }
4063 28 : if (ImageInfo.Thumbnail.size) {
4064 5 : if (read_thumbnail) {
4065 : /* not exif_iif_add_str : this is a buffer */
4066 0 : exif_iif_add_tag(&ImageInfo, SECTION_THUMBNAIL, "THUMBNAIL", TAG_NONE, TAG_FMT_UNDEFINED, ImageInfo.Thumbnail.size, ImageInfo.Thumbnail.data TSRMLS_CC);
4067 : }
4068 5 : if (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
4069 : /* try to evaluate if thumbnail data is present */
4070 5 : exif_scan_thumbnail(&ImageInfo TSRMLS_CC);
4071 : }
4072 5 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Thumbnail.FileType", ImageInfo.Thumbnail.filetype TSRMLS_CC);
4073 5 : exif_iif_add_str(&ImageInfo, SECTION_COMPUTED, "Thumbnail.MimeType", (char*)php_image_type_to_mime_type(ImageInfo.Thumbnail.filetype) TSRMLS_CC);
4074 : }
4075 28 : if (ImageInfo.Thumbnail.width && ImageInfo.Thumbnail.height) {
4076 0 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Thumbnail.Height", ImageInfo.Thumbnail.height TSRMLS_CC);
4077 0 : exif_iif_add_int(&ImageInfo, SECTION_COMPUTED, "Thumbnail.Width", ImageInfo.Thumbnail.width TSRMLS_CC);
4078 : }
4079 28 : EFREE_IF(sections_str);
4080 :
4081 : #ifdef EXIF_DEBUG
4082 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Adding image infos");
4083 : #endif
4084 :
4085 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_FILE TSRMLS_CC);
4086 28 : add_assoc_image_info(return_value, 1, &ImageInfo, SECTION_COMPUTED TSRMLS_CC);
4087 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_ANY_TAG TSRMLS_CC);
4088 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_IFD0 TSRMLS_CC);
4089 28 : add_assoc_image_info(return_value, 1, &ImageInfo, SECTION_THUMBNAIL TSRMLS_CC);
4090 28 : add_assoc_image_info(return_value, 1, &ImageInfo, SECTION_COMMENT TSRMLS_CC);
4091 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_EXIF TSRMLS_CC);
4092 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_GPS TSRMLS_CC);
4093 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_INTEROP TSRMLS_CC);
4094 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_FPIX TSRMLS_CC);
4095 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_APP12 TSRMLS_CC);
4096 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_WINXP TSRMLS_CC);
4097 28 : add_assoc_image_info(return_value, sub_arrays, &ImageInfo, SECTION_MAKERNOTE TSRMLS_CC);
4098 :
4099 : #ifdef EXIF_DEBUG
4100 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Discarding info");
4101 : #endif
4102 :
4103 28 : exif_discard_imageinfo(&ImageInfo);
4104 :
4105 : #ifdef EXIF_DEBUG
4106 : php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(p_name), E_NOTICE, "done");
4107 : #endif
4108 : }
4109 : /* }}} */
4110 :
4111 : /* {{{ proto string exif_thumbnail(string filename [, &width, &height [, &imagetype]])
4112 : Reads the embedded thumbnail */
4113 : PHP_FUNCTION(exif_thumbnail)
4114 1 : {
4115 1 : zval *p_width = 0, *p_height = 0, *p_imagetype = 0;
4116 : char *p_name;
4117 1 : int p_name_len, ret, arg_c = ZEND_NUM_ARGS();
4118 : image_info_type ImageInfo;
4119 :
4120 1 : memset(&ImageInfo, 0, sizeof(ImageInfo));
4121 :
4122 1 : if (arg_c!=1 && arg_c!=3 && arg_c!=4) {
4123 0 : WRONG_PARAM_COUNT;
4124 : }
4125 :
4126 1 : if (zend_parse_parameters(arg_c TSRMLS_CC, "s|z/z/z/", &p_name, &p_name_len, &p_width, &p_height, &p_imagetype) == FAILURE) {
4127 0 : return;
4128 : }
4129 :
4130 1 : ret = exif_read_file(&ImageInfo, p_name, 1, 0 TSRMLS_CC);
4131 1 : if (ret==FALSE) {
4132 0 : exif_discard_imageinfo(&ImageInfo);
4133 0 : RETURN_FALSE;
4134 : }
4135 :
4136 : #ifdef EXIF_DEBUG
4137 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Thumbnail data %d %d %d, %d x %d", ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size, ImageInfo.Thumbnail.filetype, ImageInfo.Thumbnail.width, ImageInfo.Thumbnail.height);
4138 : #endif
4139 1 : if (!ImageInfo.Thumbnail.data || !ImageInfo.Thumbnail.size) {
4140 0 : exif_discard_imageinfo(&ImageInfo);
4141 0 : RETURN_FALSE;
4142 : }
4143 :
4144 : #ifdef EXIF_DEBUG
4145 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Returning thumbnail(%d)", ImageInfo.Thumbnail.size);
4146 : #endif
4147 :
4148 1 : ZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size, 1);
4149 1 : if (arg_c >= 3) {
4150 0 : if (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
4151 0 : exif_scan_thumbnail(&ImageInfo TSRMLS_CC);
4152 : }
4153 0 : zval_dtor(p_width);
4154 0 : zval_dtor(p_height);
4155 0 : ZVAL_LONG(p_width, ImageInfo.Thumbnail.width);
4156 0 : ZVAL_LONG(p_height, ImageInfo.Thumbnail.height);
4157 : }
4158 1 : if (arg_c >= 4) {
4159 0 : zval_dtor(p_imagetype);
4160 0 : ZVAL_LONG(p_imagetype, ImageInfo.Thumbnail.filetype);
4161 : }
4162 :
4163 : #ifdef EXIF_DEBUG
4164 : exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Discarding info");
4165 : #endif
4166 :
4167 1 : exif_discard_imageinfo(&ImageInfo);
4168 :
4169 : #ifdef EXIF_DEBUG
4170 : php_error_docref1(NULL TSRMLS_CC, p_name, E_NOTICE, "Done");
4171 : #endif
4172 : }
4173 : /* }}} */
4174 :
4175 : /* {{{ proto int exif_imagetype(string imagefile)
4176 : Get the type of an image */
4177 : PHP_FUNCTION(exif_imagetype)
4178 30 : {
4179 : zval **arg1;
4180 : php_stream * stream;
4181 30 : int itype = 0;
4182 :
4183 30 : if (ZEND_NUM_ARGS() != 1)
4184 2 : WRONG_PARAM_COUNT;
4185 :
4186 28 : if (zend_get_parameters_ex(1, &arg1) == FAILURE)
4187 0 : WRONG_PARAM_COUNT;
4188 :
4189 28 : convert_to_string_ex(arg1);
4190 28 : stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", IGNORE_PATH|ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL);
4191 :
4192 28 : if (stream == NULL) {
4193 27 : RETURN_FALSE;
4194 : }
4195 :
4196 1 : itype = php_getimagetype(stream, NULL TSRMLS_CC);
4197 :
4198 1 : php_stream_close(stream);
4199 :
4200 1 : if (itype == IMAGE_FILETYPE_UNKNOWN) {
4201 0 : RETURN_FALSE;
4202 : } else {
4203 1 : ZVAL_LONG(return_value, itype);
4204 : }
4205 : }
4206 : /* }}} */
4207 :
4208 : #endif
4209 :
4210 : /*
4211 : * Local variables:
4212 : * tab-width: 4
4213 : * c-basic-offset: 4
4214 : * End:
4215 : * vim600: sw=4 ts=4 tw=78 fdm=marker
4216 : * vim<600: sw=4 ts=4 tw=78
4217 : */
|