commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Sova (JIRA)" <j...@apache.org>
Subject [jira] Updated: (FILEUPLOAD-135) InputStream created with Streaming API returns EOF on first read() for short files uploaded from FireFox over HTTPS
Date Tue, 29 May 2007 17:47:16 GMT

     [ https://issues.apache.org/jira/browse/FILEUPLOAD-135?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Alexander Sova updated FILEUPLOAD-135:
--------------------------------------

    Description: 
This problem happens only with files shorer then boundary string generated by browser and
only with Firefox using HTTPS protocol.
For some reason in this particular environment inputStream.read() in MultipartStream.ItemInputStream.makeAvailable()
reads not whole HTTP response body, but only file content before boundary string. 
I've created a patch fixing this issue.

  was:
I was able to reproduce this problem happens only with files shorer then boundary string generated
by browser and only with Firefox using HTTPS protocol.
For some reason in this particular environment inputStream.read() in MultipartStream.ItemInputStream.makeAvailable()
reads not whole HTTP response body, but only file content before boundary string. 
I've created a patch fixing this issue.


The problem is not with content of HTTP response, but with original InputStream behavior.
InputStream.read() may read not whole buffer or whole content of input stream, but just part
of it. If this part is shorter then boundary string (but still greater then 0) ItemInputStream.read()
returns -1.

I was able to reproduce it only with small file (10 bytes) using FireFox 1.5.0.11 and HTTPS.
I think I can simulate this by developing custom InputStream, but it could take some time.

Here is fragment of my code where I test the upload:

    protected byte[] getBoundary(String contentType) 
    {
        ParameterParser parser = new ParameterParser();
        parser.setLowerCaseNames(true);
        // Parameter parser can handle null input
        Map params = parser.parse(contentType, ';');
        String boundaryStr = (String) params.get("boundary");

        if (boundaryStr == null) {
            return null;
        }
        byte[] boundary;
        try {
            boundary = boundaryStr.getBytes("ISO-8859-1");
        } catch (UnsupportedEncodingException e) {
            boundary = boundaryStr.getBytes();
        }
        return boundary;
    }

    private void testFileUpload(HttpServletRequest req)
    {
        try 
        {
            byte[] boundary = getBoundary(req.getHeader("Content-Type"));
            System.out.println("Boundary: " + new String(boundary));
            MultipartStream multipartStream = new MultipartStream(req.getInputStream(), boundary);
            boolean nextPart = multipartStream.skipPreamble();
            OutputStream output = System.out;
            while(nextPart) 
            {
                //header = chunks.readHeader();
                System.out.println("!" + multipartStream.readHeaders() + "!");

                multipartStream.readBodyData(output);
                nextPart = multipartStream.readBoundary();
            }
        }
        catch(Exception e) 
        {
            e.printStackTrace();
        }
    }


> InputStream created with Streaming API returns EOF on first read() for short files uploaded
from FireFox over HTTPS
> -------------------------------------------------------------------------------------------------------------------
>
>                 Key: FILEUPLOAD-135
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-135
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.2, 1.2.1
>         Environment: Windows XP
> Browser: Firefox 1.5.0.11
> Protocol: HTTPS
>            Reporter: Alexander Sova
>         Attachments: commons-fileupload-1.1-bug-short-file-eof.patch, commons-fileupload-1.2-bug-short-file-eof.patch
>
>
> This problem happens only with files shorer then boundary string generated by browser
and only with Firefox using HTTPS protocol.
> For some reason in this particular environment inputStream.read() in MultipartStream.ItemInputStream.makeAvailable()
reads not whole HTTP response body, but only file content before boundary string. 
> I've created a patch fixing this issue.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message