[ 
https://issues.apache.org/jira/browse/CRYPTO-125?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15864349#comment-15864349
 ] 

Marcelo Vanzin commented on CRYPTO-125:
---------------------------------------

Hi there,

I don't think this fix is correct. The issue here is that 
{{CryptoOutputStream}} is not really following the API defined by 
{{WritableByteChannel}}. That API allows the channel to write less data than 
available in the input buffer (and the calling code needs to be able to handle 
that situation). That's required for non-blocking I/O.

This change will cause really high CPU usage if the underlying channel is 
non-blocking and is not ready for write, and will undesirably block I/O threads 
in that situation (e.g., instead of giving control back to the application so 
it can write to other channels that are ready, it will go into a busy loop 
until this one output channel becomes ready).

> CryptoOutputStream does not call write in a loop when underlying channel 
> works in non-block mode.
> -------------------------------------------------------------------------------------------------
>
>                 Key: CRYPTO-125
>                 URL: https://issues.apache.org/jira/browse/CRYPTO-125
>             Project: Commons Crypto
>          Issue Type: Bug
>          Components: Stream
>    Affects Versions: 1.0.0
>            Reporter: Junjie Chen
>            Assignee: Junjie Chen
>             Fix For: 1.1.0
>
>
> The encrypt function call output.write without loop which lead to data loss 
> when creating the output encryption stream with a SocketChannel and works in 
> non-block mode.
> As suggested, it should be call as following way:
> while(buf.hasRemaining()) {
>     channel.write(buf);
> }



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to