@@ -361,6 +361,54 @@ php_libxml_input_buffer_create_filename(const char *URI, xmlCharEncoding enc)
361
361
return (NULL );
362
362
}
363
363
364
+ /* Check if there's been an external transport protocol with an encoding information */
365
+ if (enc == XML_CHAR_ENCODING_NONE ) {
366
+ php_stream * s = (php_stream * ) context ;
367
+
368
+ if (Z_TYPE (s -> wrapperdata ) == IS_ARRAY ) {
369
+ zval * header ;
370
+
371
+ ZEND_HASH_FOREACH_VAL_IND (Z_ARRVAL (s -> wrapperdata ), header ) {
372
+ const char buf [] = "Content-Type:" ;
373
+ if (Z_TYPE_P (header ) == IS_STRING &&
374
+ !zend_binary_strncasecmp (Z_STRVAL_P (header ), Z_STRLEN_P (header ), buf , sizeof (buf )- 1 , sizeof (buf )- 1 )) {
375
+ char * needle = estrdup ("charset=" );
376
+ char * haystack = estrndup (Z_STRVAL_P (header ), Z_STRLEN_P (header ));
377
+ char * encoding = php_stristr (haystack , needle , Z_STRLEN_P (header ), sizeof ("charset=" )- 1 );
378
+
379
+ if (encoding ) {
380
+ char * end ;
381
+
382
+ encoding += sizeof ("charset=" )- 1 ;
383
+ if (* encoding == '"' ) {
384
+ encoding ++ ;
385
+ }
386
+ end = strchr (encoding , ';' );
387
+ if (end == NULL ) {
388
+ end = encoding + strlen (encoding );
389
+ }
390
+ end -- ; /* end == encoding-1 isn't a buffer underrun */
391
+ while (* end == ' ' || * end == '\t' ) {
392
+ end -- ;
393
+ }
394
+ if (* end == '"' ) {
395
+ end -- ;
396
+ }
397
+ if (encoding >= end ) continue ;
398
+ * (end + 1 ) = '\0' ;
399
+ enc = xmlParseCharEncoding (encoding );
400
+ if (enc <= XML_CHAR_ENCODING_NONE ) {
401
+ enc = XML_CHAR_ENCODING_NONE ;
402
+ }
403
+ }
404
+ efree (haystack );
405
+ efree (needle );
406
+ break ; /* found content-type */
407
+ }
408
+ } ZEND_HASH_FOREACH_END ();
409
+ }
410
+ }
411
+
364
412
/* Allocate the Input buffer front-end. */
365
413
ret = xmlAllocParserInputBuffer (enc );
366
414
if (ret != NULL ) {
0 commit comments