[
https://issues.apache.org/jira/browse/EXEC-92?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14364409#comment-14364409
]
BELUGA BEHR edited comment on EXEC-92 at 3/17/15 1:55 AM:
----------------------------------------------------------
Like I said, I'm just mimicking IOUtils, so if a check for zero-length is
required, then that should be addressed with that project too.
I'm not sure there's anything to "protect" against. Any implementation of an
OutputStream is going to do some sort of "for (0..length)" and if length is
zero, nothing happens.
BufferedInputStream is an example of this:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/InputStream.java#InputStream.read%28byte%5B%5D%2Cint%2Cint%29
was (Author: belugabehr):
Like I said, I'm just mimicking IOUtils, so if a check for zero-length is
required, then that should be addressed with that project too.
I'm not sure there's anything to "protect" against. Any implementation of an
OutputStream is going to do some sort of "for (0..length)" and if length is
zero, nothing happens.
BufferedInputStream is an example of this:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/io/FilterInputStream.java#FilterInputStream.read%28byte%5B%5D%2Cint%2Cint%29
> StreamPumper - Check For EOF
> ----------------------------
>
> Key: EXEC-92
> URL: https://issues.apache.org/jira/browse/EXEC-92
> Project: Commons Exec
> Issue Type: Bug
> Affects Versions: 1.3
> Reporter: BELUGA BEHR
> Fix For: 1.4
>
> Attachments: StreamPumper.java.patch
>
>
> When the StreamPumper is copying data from the InputStream to the
> OutputStream, it would be safer to check for EOF instead of a read size
> greater than zero to protect against InputStream implementations that don't
> respect the contract as defined in Java core JavaDoc.
> Patch Included. I took code from the copy method of the IOUtils class.
> {code:title=StreamPumper.java|borderStyle=solid}
> while ((length = is.read(buf)) > 0)
> {
> os.write(buf, 0, length);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)