[
https://issues.apache.org/jira/browse/COMPRESS-584?focusedWorklogId=633365&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-633365
]
ASF GitHub Bot logged work on COMPRESS-584:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 04/Aug/21 08:53
Start Date: 04/Aug/21 08:53
Worklog Time Spent: 10m
Work Description: matthijsln commented on pull request #214:
URL: https://github.com/apache/commons-compress/pull/214#issuecomment-892485686
> > Note that for
[COMPRESS-585](https://issues.apache.org/jira/browse/COMPRESS-585) I propose
removing the limit to the max bytes read to COPY_BUF_SIZE altogether (the same
as the `IOUtils.readRange(InputStream,int)` method) because the calling code
does not expect the method to return less than `len` bytes unless EOF is
encountered.
> > With the limit removed we can use the
[f8587ff](https://github.com/apache/commons-compress/commit/f8587ff16469bcda58db57baafabc9e4639e7f93)
version.
>
> No. The `COPY_BUF_SIZE` is not a limit. It's just a limit of the buffer's
size.
> Note that the `ByteBuffer b` is just a buffer for copying the bytes.
That's why the `rewind` is nessary here - we can not always ensure the `len` is
less than `COPY_BUF_SIZE`.
Ah, I think I get it :) The problem in COMPRESS-585 is the same as
COMPRESS-584 then. The original intent of the method is to return a byte array
of `len` bytes or less if EOF was encountered. I mistakenly thought it was
designed to return max COPY_BUF_SIZE even of no EOF.
To summarize:
- If the first `read()` call returned less than `len`, for the next `read()`
call it could read more than `len`. This can happen reading from a socket.
- If `len` is more than COPY_BUF_SIZE, it would read in more loops and may
read more than `len`. This can happen with an entry comment longer than
COPY_BUF_SIZE.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 633365)
Time Spent: 2.5h (was: 2h 20m)
> IOUtils.readRange() can read more from a channel than asked for
> ---------------------------------------------------------------
>
> Key: COMPRESS-584
> URL: https://issues.apache.org/jira/browse/COMPRESS-584
> Project: Commons Compress
> Issue Type: Bug
> Components: Archivers
> Affects Versions: 1.21
> Reporter: Matthijs Laan
> Priority: Major
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> When {{IOUtils.readRange(ReadableByteChannel,int)}} gets less than the number
> of bytes asked for in the first read call it does not reduce the buffer size
> for the next read call and may read more than asked for.
> This situation is rare when using a {{FileChannel}} but I wrote a
> {{SeekableByteChannel}} backed by a URI using HTTP range requests and reading
> from a socket can often return less bytes than asked for. When I used this
> channel to read a {{ZipFile}} it only read the ZIP central directory
> partially sometimes because {{IOUtils.readRange()}} called from
> {{ZipFile.readCentralDirectoryEntry()}} read more bytes than asked for and it
> stopped parsing directory entries.
> Fix: [https://github.com/apache/commons-compress/pull/214]
--
This message was sent by Atlassian Jira
(v8.3.4#803005)