cvs: php4(PHP_4_2_0) /ext/exif exif.c /ext/exif/tests 003.phpt test3.jpg

From: Date: Sun, 07 Apr 2002 19:45:37 +0000
Subject: cvs: php4(PHP_4_2_0) /ext/exif exif.c /ext/exif/tests 003.phpt test3.jpg
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10947@lists.php.net to get a copy of this message
helly Sun Apr 7 15:45:37 2002 EDT Added files: (Branch: PHP_4_2_0) /php4/ext/exif/tests 003.phpt test3.jpg Modified files: /php4/ext/exif exif.c Log: -found userland solution to fix UNICODE comments (see tests/003.phpt) #solution from HEAD would mean new functionality #so this fix makes it work without adding new functionality Index: php4/ext/exif/exif.c diff -u php4/ext/exif/exif.c:1.52.2.5 php4/ext/exif/exif.c:1.52.2.6 --- php4/ext/exif/exif.c:1.52.2.5 Thu Apr 4 15:42:47 2002 +++ php4/ext/exif/exif.c Sun Apr 7 15:45:36 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: exif.c,v 1.52.2.5 2002/04/04 20:42:47 helly Exp $ */ +/* $Id: exif.c,v 1.52.2.6 2002/04/07 19:45:36 helly Exp $ */ /* ToDos * @@ -720,6 +720,7 @@ int motorola_intel; /* 1 Motorola; 0 Intel */ char *UserComment; + int UserCommentLength; char UserCommentEncoding[12]; char *Thumbnail; @@ -767,7 +768,7 @@ case TAG_FMT_STRING: if ( value) { - length = php_strnlen(value,length); + /*length = php_strnlen(value,length); would disable UNICODE comments*/ info_value->length = length; info_value->value.s = estrndup(value,length); } else { @@ -917,7 +918,7 @@ void add_assoc_image_info( pval *value, int sub_array, image_info_type *image_info, int section_index) { char buffer[64], *val, *name, uname[64]; - int idx=0, unknown=0; + int idx=0, unknown=0, len; image_info_value *info_value; if ( image_info->info_list[section_index].count) @@ -959,11 +960,16 @@ break; case TAG_FMT_STRING: - if ( !(val = info_value->value.s)) val = ""; + if ( !(val = info_value->value.s)) { + val = ""; + len = 0; + } else { + len = info_value->length; + } if (section_index==SECTION_COMMENT) { - add_index_string(tmpi, idx++, val, 1); + add_index_stringl(tmpi, idx++, val, len, 1); } else { - add_assoc_string(tmpi, name, val, 1); + add_assoc_stringl(tmpi, name, val, len , 1); } break; @@ -1065,7 +1071,7 @@ */ static void exif_process_COM (image_info_type *image_info, uchar *value, int length) { - exif_add_image_info( image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_STRING, length-2, value+2); + exif_add_image_info( image_info, SECTION_COMMENT, "Comment", TAG_COMPUTED_VALUE, TAG_FMT_STRING, php_strnlen(value+2, length-2), value+2); } /* }}} */ @@ -1254,7 +1260,7 @@ * Process UserComment in IFD. */ static int exif_process_user_comment(char **pszInfoPtr,char *szEncoding,char *szValuePtr,int ByteCount) { - int a; + int a, size; *szEncoding = '\0'; /* Copy the comment */ @@ -1264,7 +1270,8 @@ strcpy( szEncoding, szValuePtr); szValuePtr = szValuePtr+8; ByteCount -= 8; - return exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); + size = exif_process_string_raw(pszInfoPtr, szValuePtr, ByteCount); + return size ? size-1 : 0; } if ( !memcmp(szValuePtr, "ASCII\0\0\0", 8)) { strcpy( szEncoding, szValuePtr); @@ -1283,7 +1290,8 @@ if (a) for (a=ByteCount-1;a && szValuePtr[a]==' ';a--) (szValuePtr)[a] = '\0'; /* normal text without encoding */ - return exif_process_string(pszInfoPtr, szValuePtr, ByteCount); + size = exif_process_string(pszInfoPtr, szValuePtr, ByteCount); + return size ? size-1 : 0; } /* }}} */ @@ -1429,7 +1437,7 @@ break; case TAG_USERCOMMENT: - exif_process_user_comment(&(ImageInfo->UserComment),ImageInfo->UserCommentEncoding,value_ptr,byte_count); + ImageInfo->UserCommentLength = exif_process_user_comment(&(ImageInfo->UserComment),ImageInfo->UserCommentEncoding,value_ptr,byte_count); break; /* this is only a comment if type is string! */ @@ -1544,6 +1552,9 @@ /* correctly would be to set components as length * but we are ignoring length for those types where it is not the same as byte_count */ + if (format==TAG_FMT_STRING) { + byte_count = php_strnlen(value_ptr,byte_count); + } exif_add_image_info( ImageInfo, section_index, exif_get_tagname(tag,tagname), tag, format, byte_count, value_ptr); if ( outside) efree( outside); } @@ -2266,7 +2277,7 @@ exif_add_image_info( &ImageInfo, SECTION_COMPUTED, "FocusDistance", TAG_NONE, TAG_FMT_STRING, strlen(tmp), tmp); } if (ImageInfo.UserComment) { - exif_add_image_info( &ImageInfo, SECTION_COMPUTED, "UserComment", TAG_NONE, TAG_FMT_STRING, strlen(ImageInfo.UserComment), ImageInfo.UserComment); + exif_add_image_info( &ImageInfo, SECTION_COMPUTED, "UserComment", TAG_NONE, TAG_FMT_STRING, ImageInfo.UserCommentLength, ImageInfo.UserComment); if ( (len=strlen(ImageInfo.UserCommentEncoding))) { exif_add_image_info( &ImageInfo, SECTION_COMPUTED, "UserCommentEncoding", TAG_NONE, TAG_FMT_STRING, len, ImageInfo.UserCommentEncoding); } Index: php4/ext/exif/tests/003.phpt +++ php4/ext/exif/tests/003.phpt --TEST-- Check for exif_read_data --SKIPIF-- <?php if (!extension_loaded("exif")) print "skip";?> --POST-- --GET-- --FILE-- <?php /* test1.jpg is a 1*1 image that does not contain any Exif/Comment information test2.jpg is the same image but contains Exif/Comment information and a copy of test1.jpg as a thumbnail. test3.jpg is the same as test2.jpg but with a UNICODE USerComment: &Auml;&Ouml;&&Uuml;&szlig;&auml;&ouml;&uuml; */ $image = exif_read_data('./ext/exif/tests/test3.jpg','',true,false); $accept = ''; foreach($image as $idx=>$section) { $accept .= $section; foreach($section as $name=>$value) { if ( $idx!='FILE' || $name!='FileDateTime') { $accept .= substr($name,0,2); $accept .= $value; } } } echo $accept; ?> --EXPECT-- ArrayFitest3.jpgFi1237Fi2SeANY_TAG, IFD0, THUMBNAIL, COMMENTArrayhtwidth="1" height="1"He1Wi1Is1UsÄÖÜßäöüUsUNICODECoPhoto (c) M.Boerger, Edited by M.Boerger.CoPhoto (c) M.BoergerCoEdited by M.Boerger.ArrayCoPhoto (c) M.BoergerUsUNICODEArrayJP134JP523Array0Comment #1.1Comment #2.2Comment #3end

« previous php.cvs (#10947) next »