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

Petr Havlena edited comment on CXF-7025 at 8/26/16 1:28 PM:
------------------------------------------------------------

i run on https and in my case read returns 1, so not whole 2K is buffered into 
byte array and from java doc 
https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[]) 
there is no guarantee that whole buffer will be read. moreover read can returns 
-1 and IOUtils.newStringFromBytes will fail if that happens. you assume that 
read will return whole 2K, for example 
http://stackoverflow.com/questions/6160432/java-inputstream-reading-problem


was (Author: havlenapetr):
i run on https and in my case read returns 1, so not whole 2K is buffered into 
byte array and from java doc 
https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[]) 
there is no guarantee that whole buffer will be read. moreover read can returns 
-1 and IOUtils.newStringFromBytes will fail if that happens. current code could 
be rewritten into this same bad impl:

byte buf[] = new byte[2048];
in.read(buf);
String msg = IOUtils.newStringFromBytes(buf, 0, 2048);
in.unread(buf, 0, 2048);

because you assume that read will return whole 2K, for example 
http://stackoverflow.com/questions/6160432/java-inputstream-reading-problem

> Find boundary from InputStream
> ------------------------------
>
>                 Key: CXF-7025
>                 URL: https://issues.apache.org/jira/browse/CXF-7025
>             Project: CXF
>          Issue Type: Bug
>          Components: Core, JAX-RS
>    Affects Versions: 3.1.4
>            Reporter: Petr Havlena
>
> in method AttachmentDeserializer.findBoundaryFromInputStream line: "int i = 
> in.read(buf)" is invalid, because read returns "some number of bytes from the 
> input stream and stores them into the buffer array b" so you should check 
> result from read method and repeat reading if neccesary



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to