From owner-freebsd-www@FreeBSD.ORG Thu Mar 5 21:10:02 2009 Return-Path: Delivered-To: freebsd-www@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 058C51065679 for ; Thu, 5 Mar 2009 21:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id D58D68FC1C for ; Thu, 5 Mar 2009 21:10:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n25LA1pa079232 for ; Thu, 5 Mar 2009 21:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n25LA1WC079231; Thu, 5 Mar 2009 21:10:01 GMT (envelope-from gnats) Resent-Date: Thu, 5 Mar 2009 21:10:01 GMT Resent-Message-Id: <200903052110.n25LA1WC079231@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-www@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, David Horn Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D38D91065670 for ; Thu, 5 Mar 2009 21:06:01 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id B839B8FC15 for ; Thu, 5 Mar 2009 21:06:01 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n25L61lQ075921 for ; Thu, 5 Mar 2009 21:06:01 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n25L61PY075920; Thu, 5 Mar 2009 21:06:01 GMT (envelope-from nobody) Message-Id: <200903052106.n25L61PY075920@www.freebsd.org> Date: Thu, 5 Mar 2009 21:06:01 GMT From: David Horn To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: www/132344: [patch] www/en/cgi/query-pr.cgi broken base64 attachments X-BeenThere: freebsd-www@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD Project Webmasters List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2009 21:10:02 -0000 >Number: 132344 >Category: www >Synopsis: [patch] www/en/cgi/query-pr.cgi broken base64 attachments >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-www >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 05 21:10:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: David Horn >Release: 7.1 >Organization: >Environment: n/a >Description: The query-pr.cgi script interface to gnats tries very hard to decode and display attachments properly. www/en/cgi/query-pr.cgi Unfortunately, MIME headers do not always play nice, and there are many instances of inproper display of base64 encoded attachments. The real issue is that if either "X-Attachment-Id:" or "Content-Disposition:" headers occur after "Content-Transfer-Encoding" headers, then decode_base64() fails, and displays unprintable characters. example pr's that do not display base64 attachments properly: ports/130991 ports/130144 ports/130000 >How-To-Repeat: Go to http://www.freebsd.org/cgi/query-pr.cgi?pr=130144 in your web browser, and notice that the attachment displays unprintable characters. Repeat for 130144 and 130000 as slightly different examples. >Fix: -Parse out the X-Attachment-Id header if found -do not assume that content-transfer-encoding is the last header -Check for nonprintables on result of decode_base64() This fix seems to work for all broken base64 attachment pr's that I have found. To test the check for nonprintables, just mangle one of the prs by adding "X-Broken-Header: asdfasdf" to the end of the mime header just before the base64 payload starts, and the code will break again, but at least will be caught by the :isascii: check for nonprintables Unified diff attached. Patch attached with submission follows: --- query-pr.cgi.original 2009-03-05 15:26:02.000000000 -0500 +++ query-pr.cgi 2009-03-05 15:47:03.000000000 -0500 @@ -610,7 +610,13 @@ if ($patchname =~ /$binary_filetypes/) { $outp = "(Binary attachment not viewable.)\n"; } else { + $outp =~ s/^X-Attachment-Id: \x0a?//i; + $outp =~ s/^f_.{7}[a-z]?[0-9]*//i; + $outp =~ s/^file[0-9]*//i; $outp = decode_base64($outp); + if ($outp =~ /[[:^ascii:]]/) { + $outp = "(Unable to decode attachment using base64.)\n"; + } } $outp = "--- $patchname begins here ---\n" @@ -638,7 +644,9 @@ } next; } else { - $mime_endheader = 1; + # XXX: Commented out to fix an issue if transfer-encoding is not the + # last header before base64 payload really starts. + #$mime_endheader = 1; if ($mime_headers{'transfer-encoding'}) { my $enc = $mime_headers{'transfer-encoding'}; if ($enc =~ /^\s*["']?base64["']?\s*$/i) { @@ -1004,7 +1012,14 @@ $inpatch = 0; $mime_boundary = undef; if ($outp ne "") { - print decode_base64($outp); + $outp =~ s/^X-Attachment-Id: \x0a?//i; + $outp =~ s/^f_.{7}[a-z]?[0-9]*//i; + $outp =~ s/^file[0-9]*//i; + my $decoded_file = decode_base64($outp); + if ($decoded_file =~ /[[:^ascii:]]/) { + $decoded_file = $outp; + } + print ($decoded_file); $outp = ""; } return -1; >Release-Note: >Audit-Trail: >Unformatted: