You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix concurrency issue in `IOUtils.skip`
This patch addresses a concurrency problem in `IOUtils.skip`, as reported in [COMPRESS-666](https://issues.apache.org/jira/browse/COMPRESS-666) and [COMPRESS-697](https://issues.apache.org/jira/browse/COMPRESS-697).
Previously, `IOUtils.skip` relied on `InputStream#read` to skip bytes, using a buffer shared across **all** threads. Although `IOUtils.skip` itself does not consume the data read, certain `InputStream` implementations (e.g. `ChecksumInputStream`) may process that data internally.
In concurrent scenarios, this shared buffer could be overwritten by another thread between the `read` and the subsequent internal processing (such as checksum calculation), leading to incorrect behavior.
This change reverts commit c12eaff and restores the use of a **per-thread buffer** in `IOUtils.skip`, ensuring thread safety and correct behavior in concurrent environments.
* Adds a reentrancy guard to the thread-local pool
* Apply suggestion from @Copilot (1)
Co-authored-by: Copilot <[email protected]>
* Apply suggestions from @Copilot (2)
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>
Copy file name to clipboardExpand all lines: src/changes/changes.xml
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,7 @@ The <action> type attribute can be add,update,fix,remove.
56
56
<actiontype="fix"dev="pkarwasz"due-to="Piotr P. Karwasz">IOUtils.toByteArray(InputStream) now throws IOException on byte array overflow.</action>
57
57
<actiontype="fix"dev="ggregory"due-to="Gary Gregory, Piotr P. Karwasz">Javadoc general improvements.</action>
58
58
<actiontype="fix"dev="ggregory"due-to="Piotr P. Karwasz">IOUtils.toByteArray() now throws EOFException when not enough data is available #796.</action>
59
+
<actiontype="fix"dev="pkarwasz"due-to="Piotr P. Karwasz">Fix IOUtils.skip() usage in concurrent scenarios.</action>
59
60
<!-- ADD -->
60
61
<actiondev="ggregory"type="add"due-to="strangelookingnerd, Gary Gregory">FileUtils#byteCountToDisplaySize() supports Zettabyte, Yottabyte, Ronnabyte and Quettabyte #763.</action>
61
62
<actiondev="ggregory"type="add"due-to="strangelookingnerd, Gary Gregory">Add org.apache.commons.io.FileUtils.ONE_RB #763.</action>
// Writer. Each method should take at least one of these as a parameter,
133
133
// or return one of them.
134
134
135
+
/**
136
+
* Holder for per-thread internal scratch buffers.
137
+
*
138
+
* <p>Buffers are created lazily and reused within the same thread to reduce allocation overhead. In the rare case of reentrant access, a temporary buffer
139
+
* is allocated to avoid data corruption.</p>
140
+
*
141
+
* <p>Typical usage:</p>
142
+
*
143
+
* <pre>{@code
144
+
* final byte[] buffer = ScratchBufferHolder.getScratchByteArray();
0 commit comments