Skip to content

Commit fb6dd55

Browse files
committed
Merge r1884505, r1915625 from trunk:
The Microsoft OOXML format uses xml packaged into a zip file, and has mimetypes like: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet This mimetypes contains 'xml', but is unfortunately not an xml file. xml2enc processes these files (in particular, when mod_proxy_html is used), typically resulting in them being corrupted as it seems to attempt to perform a ISO-8859-1 to UTF-8 conversion on them. * modules/filters/mod_xml2enc.c (xml2enc_ffunc): Restrict test for XML types to matching "+xml". Submitted by: Joseph Heenan <joseph.heenan fintechlabs.io>, jorton PR: 64339 Reviewed by: jorton, ylavic, gbechis Github: closes #410 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1916412 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8a47586 commit fb6dd55

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

changes-entries/pr64339.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*) mod_xml2enc: Update check to accept any text/ media type
2+
or any XML media type per RFC 7303, avoiding
3+
corruption of Microsoft OOXML formats. PR 64339.
4+
[Joseph Heenan <joseph.heenan fintechlabs.io>, Joe Orton]

modules/filters/mod_xml2enc.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ static apr_status_t xml2enc_ffunc(ap_filter_t* f, apr_bucket_brigade* bb)
323323
apr_bucket* bstart;
324324
apr_size_t insz = 0;
325325
int pending_meta = 0;
326-
char *ctype;
326+
char *mtype;
327327
char *p;
328328

329329
if (!ctx || !f->r->content_type) {
@@ -332,13 +332,17 @@ static apr_status_t xml2enc_ffunc(ap_filter_t* f, apr_bucket_brigade* bb)
332332
return ap_pass_brigade(f->next, bb) ;
333333
}
334334

335-
ctype = apr_pstrdup(f->r->pool, f->r->content_type);
336-
for (p = ctype; *p; ++p)
337-
if (isupper(*p))
338-
*p = tolower(*p);
339-
340-
/* only act if starts-with "text/" or contains "xml" */
341-
if (strncmp(ctype, "text/", 5) && !strstr(ctype, "xml")) {
335+
/* Extract the media type, ignoring parameters in content-type. */
336+
mtype = apr_pstrdup(f->r->pool, f->r->content_type);
337+
if ((p = ap_strchr(mtype, ';')) != NULL) *p = '\0';
338+
ap_str_tolower(mtype);
339+
340+
/* Accept text/ types, plus any XML media type per RFC 7303. */
341+
if (!(strncmp(mtype, "text/", 5) == 0
342+
|| strcmp(mtype, "application/xml") == 0
343+
|| (strlen(mtype) > 7 /* minimum 'a/b+xml' length */
344+
&& (p = strstr(mtype, "+xml")) != NULL
345+
&& strlen(p) == 4 /* ensures +xml is a suffix */))) {
342346
ap_remove_output_filter(f);
343347
return ap_pass_brigade(f->next, bb) ;
344348
}

0 commit comments

Comments
 (0)