You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Steve Loughran (JIRA)" <ji...@apache.org> on 2010/09/16 12:30:37 UTC

[jira] Created: (HTTPCORE-235) EntityUtils.toString() doesn't detect/report less content being returned than was promised

EntityUtils.toString() doesn't detect/report less content being returned than was promised
------------------------------------------------------------------------------------------

                 Key: HTTPCORE-235
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-235
             Project: HttpComponents HttpCore
          Issue Type: Bug
          Components: HttpCore
    Affects Versions: 4.0.1
            Reporter: Steve Loughran


Also on my review of EntityUtils.toString(), I see that it's code to take an input stream and a content length only uses the content length parameter to set the size of the buffer -there is no attempt to verify that the amount of data received was as expected and raise an {{IOException}} if less data arrived. 

While this code will appear to work, especially on loopback and local connections, it is flawed long-haul where connections are often dropped early. 

I propose streaming the entity content to a byte array, validating the length, then building a string in the appropriate charset from the buffer if it is valid.



-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Resolved: (HTTPCORE-235) EntityUtils.toString() doesn't detect/report less content being returned than was promised

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCORE-235?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCORE-235.
----------------------------------------

    Resolution: Invalid

> While this code will appear to work, especially on loopback and local connections, it is flawed long-haul where connections are often dropped early.

In this case an I/O exception will be thrown. Besides, the proper message delimitation is enforced by the protocol handlers. I do not think EntityUtils is the right place for this kind logic. 

Having said that, there is always a choice of using a custom HttpEntity helper for to string or to byte array conversions where additional validation logic could be implemented. 

Oleg

> EntityUtils.toString() doesn't detect/report less content being returned than was promised
> ------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-235
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-235
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 4.0.1
>            Reporter: Steve Loughran
>
> Also on my review of EntityUtils.toString(), I see that it's code to take an input stream and a content length only uses the content length parameter to set the size of the buffer -there is no attempt to verify that the amount of data received was as expected and raise an {{IOException}} if less data arrived. 
> While this code will appear to work, especially on loopback and local connections, it is flawed long-haul where connections are often dropped early. 
> I propose streaming the entity content to a byte array, validating the length, then building a string in the appropriate charset from the buffer if it is valid.

-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCORE-235) EntityUtils.toString() doesn't detect/report less content being returned than was promised

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12910301#action_12910301 ] 

Oleg Kalnichevski commented on HTTPCORE-235:
--------------------------------------------

> he root cause was my own - I was closing the connection before trying to get the data out of the response

What exactly do you mean by "closing the connection"? Calling #close() on the content input stream? If that is the case, the content codec simply consumes the remaining content in order to ensure the underlying connection could be kept-alive and re-used for subsequent requests. This is the normal mode of operation, which is not mean to cause an I/O exception of any kind. Only if an attempt is made to read form a closed stream an exception would be thrown.

Oleg

> EntityUtils.toString() doesn't detect/report less content being returned than was promised
> ------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-235
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-235
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 4.0.1
>            Reporter: Steve Loughran
>
> Also on my review of EntityUtils.toString(), I see that it's code to take an input stream and a content length only uses the content length parameter to set the size of the buffer -there is no attempt to verify that the amount of data received was as expected and raise an {{IOException}} if less data arrived. 
> While this code will appear to work, especially on loopback and local connections, it is flawed long-haul where connections are often dropped early. 
> I propose streaming the entity content to a byte array, validating the length, then building a string in the appropriate charset from the buffer if it is valid.

-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Commented: (HTTPCORE-235) EntityUtils.toString() doesn't detect/report less content being returned than was promised

Posted by "Steve Loughran (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HTTPCORE-235?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12910202#action_12910202 ] 

Steve Loughran commented on HTTPCORE-235:
-----------------------------------------

I didn't see an IOE, I saw that I was getting "" back even though the content-length was 54 octets. The root cause was my own - I was closing the connection before trying to get the data out of the response- but the whole problem wasn't surfacing in an exception, just an empty string.

I rewrote the code to do the download by creating a buffer of the exact size promised, doing a blocking read, and throwing an IOE if there was less data than promised or there was still some more data to come. Either state is an error, at least as far as I'm concerned, at least when the content-length header value >= 0

> EntityUtils.toString() doesn't detect/report less content being returned than was promised
> ------------------------------------------------------------------------------------------
>
>                 Key: HTTPCORE-235
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-235
>             Project: HttpComponents HttpCore
>          Issue Type: Bug
>          Components: HttpCore
>    Affects Versions: 4.0.1
>            Reporter: Steve Loughran
>
> Also on my review of EntityUtils.toString(), I see that it's code to take an input stream and a content length only uses the content length parameter to set the size of the buffer -there is no attempt to verify that the amount of data received was as expected and raise an {{IOException}} if less data arrived. 
> While this code will appear to work, especially on loopback and local connections, it is flawed long-haul where connections are often dropped early. 
> I propose streaming the entity content to a byte array, validating the length, then building a string in the appropriate charset from the buffer if it is valid.

-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org