Return-Path: Delivered-To: apmail-struts-issues-archive@locus.apache.org Received: (qmail 56206 invoked from network); 13 Jun 2008 21:16:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Jun 2008 21:16:27 -0000 Received: (qmail 116 invoked by uid 500); 13 Jun 2008 21:16:28 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 99981 invoked by uid 500); 13 Jun 2008 21:16:28 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 99972 invoked by uid 99); 13 Jun 2008 21:16:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jun 2008 14:16:28 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Jun 2008 21:15:47 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 4E537234C13E for ; Fri, 13 Jun 2008 14:16:05 -0700 (PDT) Message-ID: <1060210479.1213391765319.JavaMail.jira@brutus> Date: Fri, 13 Jun 2008 14:16:05 -0700 (PDT) From: "Rainer Hermanns (JIRA)" To: issues@struts.apache.org Subject: [jira] Resolved: (WW-2557) FileUploadInterceptor allows forbidden files when passed with allowed files In-Reply-To: <768166500.1205856718910.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/struts/browse/WW-2557?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Rainer Hermanns resolved WW-2557. --------------------------------- Resolution: Fixed Assignee: Rainer Hermanns patch slightly modified and applied, thanks! > FileUploadInterceptor allows forbidden files when passed with allowed files > --------------------------------------------------------------------------- > > Key: WW-2557 > URL: https://issues.apache.org/struts/browse/WW-2557 > Project: Struts 2 > Issue Type: Bug > Components: Core Interceptors > Affects Versions: 2.0.11 > Environment: Windows Vista, Java 1.6.0_05 > Reporter: Stephan Schroeder > Assignee: Rainer Hermanns > Fix For: 2.1.3 > > > Summary: If you set the "allowedTypes" parameter of FileUploadInterceptor for example to "image/jpeg" and upload a jpg file and a gif file whit the same form name > (e.g.: > <@s.form action="photoupload" method="post" enctype="multipart/form-data"> > <@s.file name="photos" label="Pictured 1"/> > <@s.file name="photos" label="Pictured 2"/> > <@s.submit/> > ) > than the gif file will be accepted too. > this is some code from the uptodate SVN repository of FileUploadInterceptor > (http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java?revision=615436&view=markup) > > 1 File[] files = multiWrapper.getFiles(inputName); > 2 if (files != null) { > 3 for (int index = 0; index < files.length; index++) { > 4 if (acceptFile(files[index], contentType[index], inputName, validation, ac.getLocale())){ > 5 parameters.put(inputName, files); > 6 parameters.put(inputName + "ContentType", contentType); > 7 parameters.put(inputName + "FileName", fileName); > 8 } > 9 } > 10} > > Bug 1) as you can see in line 4 and 5 as soon as one file is accepted the whole array is added to parameters which of course means even the files which haven't been accepted themselfs. > Improvement 1) in line 6 and 7 static string concatenations are done within a loop. This should move out of the loop. > Here is my proposal for a fix for both issues: > > File[] files = multiWrapper.getFiles(inputName); > if (files != null) { > ArrayList acceptedFiles = new ArrayList( files.length() ); > ArrayList acceptedContentTypes = new ArrayList( files.length() ); > ArrayList acceptedFileNames = new ArrayList( files.length() ); > String contentTypeName = inputName + "ContentType"; > String fileNameName = inputName + "FileName"; > for (int index = 0; index < files.length; index++) { > if (acceptFile(files[index], contentType[index], inputName, validation, ac.getLocale())){ > acceptedFiles.add( files[index] ); > acceptedContentTypes.add( contentType[index] ); > acceptedFileNames.add( fileName[index] ); > } > } > if( acceptedFiles.size()!=0 ) { > parameters.put(inputName, acceptedFiles.toArray()); > parameters.put(contentTypeName, acceptedContentTypes.toArray()); > parameters.put(fileNameName, acceptedFileNames.toArray()); > } > } > -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.