You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2025/03/21 22:41:00 UTC
[jira] [Resolved] (IO-871) IOUtils.contentEquals is incorrect when InputStream.available under-reports
[ https://issues.apache.org/jira/browse/IO-871?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory resolved IO-871.
--------------------------------
Fix Version/s: 2.19.0
Assignee: Gary D. Gregory
Resolution: Fixed
Hello [~eamonnmcmanus]
This is now fixed in git master and snapshot builds in https://repository.apache.org/content/repositories/snapshots/
Please verify and close if your use case works.
> IOUtils.contentEquals is incorrect when InputStream.available under-reports
> ---------------------------------------------------------------------------
>
> Key: IO-871
> URL: https://issues.apache.org/jira/browse/IO-871
> Project: Commons IO
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.19.0
> Reporter: Éamonn McManus
> Assignee: Gary D. Gregory
> Priority: Minor
> Fix For: 2.19.0
>
>
> A [recent change|https://github.com/apache/commons-io/commit/c832eb20796b25d8ee2437a8663616b1112cd7bd] to IOUtils.contentEquals(InputStream,InputStream) introduced a bug when at least one of the InputStream instances under-reports the number of available bytes. That is completely allowed by the contract of InputStream. I think the underlying problem may be [this line|https://github.com/apache/commons-io/blob/0d41d2fd958f28a0c4eb21afb6f34be8efa0e4fb/src/main/java/org/apache/commons/io/channels/FileChannels.java#L94] in FileChannels. There's no requirement for a ReadableByteChannel.read to return all available bytes, and therefore it is possible for one of the two reads being compared to be shorter than the other, even though the contents of the two channels are in fact equal.
> This problem showed up when importing the latest source snapshot to Google's internal repository and running all of Google's tests against it. Here is a simple repro:
> {code:java}
> assertThat(
> IOUtils.contentEquals(
> new ByteArrayInputStream("ab".getBytes()),
> new SequenceInputStream(
> new ByteArrayInputStream("a".getBytes()),
> new ByteArrayInputStream("b".getBytes()))))
> .isTrue(); {code}
> The assertion passes before this change and fails after it.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)