Changeset 25447
- Timestamp:
- 05/11/08 07:28:01 (6 days ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
haiku/trunk/src/add-ons/translators/jpeg/exif_parser.cpp
r20633 r25447 1 1 /* 2 * Copyright 2007 , Axel Dörfler, axeld@pinc-software.de. All rights reserved.2 * Copyright 2007-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 */ … … 7 7 #include "exif_parser.h" 8 8 9 #include <ReadHelper.h>10 11 #include <Message.h>12 13 9 #include <ctype.h> 10 #include <set> 14 11 #include <stdio.h> 15 12 #include <stdlib.h> 13 14 #include <Message.h> 15 16 #include <ReadHelper.h> 16 17 17 18 … … 38 39 39 40 40 static status_t parse_tiff_directory(TReadHelper& read, BMessage& target,41 const convert_tag* tags, size_t tagCount);41 static status_t parse_tiff_directory(TReadHelper& read, set<off_t>& visited, 42 BMessage& target, const convert_tag* tags, size_t tagCount); 42 43 43 44 … … 227 228 228 229 static status_t 229 parse_tiff_directory(TReadHelper& read, off_t offset, BMessage& target, 230 const convert_tag* convertTags, size_t convertTagCount) 231 { 230 parse_tiff_directory(TReadHelper& read, set<off_t>& visited, off_t offset, 231 BMessage& target, const convert_tag* convertTags, size_t convertTagCount) 232 { 233 if (visited.find(offset) != visited.end()) { 234 // The EXIF data is obviously corrupt 235 return B_BAD_DATA; 236 } 237 232 238 read.Seek(offset, SEEK_SET); 239 visited.insert(offset); 233 240 234 241 uint16 tags; … … 248 255 case TAG_SUB_DIR_OFFSET: 249 256 { 250 status_t status = parse_tiff_directory(read, target,257 status_t status = parse_tiff_directory(read, visited, target, 251 258 convertTags, convertTagCount); 252 259 if (status < B_OK) … … 264 271 break; 265 272 } 273 274 if (visited.find(nextOffset) != visited.end()) 275 return B_BAD_DATA; 276 266 277 read.Seek(nextOffset, SEEK_SET); 278 visited.insert(nextOffset); 267 279 } 268 280 … … 272 284 273 285 static status_t 274 parse_tiff_directory(TReadHelper& read, BMessage& target,286 parse_tiff_directory(TReadHelper& read, set<off_t>& visited, BMessage& target, 275 287 const convert_tag* tags, size_t tagCount) 276 288 { … … 281 293 break; 282 294 283 status_t status = parse_tiff_directory(read, offset, target,295 status_t status = parse_tiff_directory(read, visited, offset, target, 284 296 tags, tagCount); 285 297 if (status < B_OK) … … 294 306 295 307 308 /*! Converts the EXIF data that starts in \a source to a BMessage in \a target. 309 If the EXIF data is corrupt, this function will return an appropriate error 310 code. Nevertheless, there might be some data ending up in \a target that 311 was parsed until this point. 312 */ 296 313 status_t 297 314 convert_exif_to_message(BPositionIO& source, BMessage& target, … … 316 333 return B_BAD_TYPE; 317 334 318 return parse_tiff_directory(read, target, tags, tagCount); 335 set<off_t> visitedOffsets; 336 return parse_tiff_directory(read, visitedOffsets, target, tags, tagCount); 319 337 } 320 338 haiku/trunk/src/tests/add-ons/translators/exif/dump_exif.cpp
r25446 r25447 28 28 BMessage exif; 29 29 status_t status = convert_exif_to_message(source, exif); 30 if (status == B_OK) 31 exif.PrintToStream(); 30 31 exif.PrintToStream(); 32 // even if it failed, some data might end up in the message 32 33 33 34 return status;
