aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-03-25 00:47:15 +0000
committerPJ Fanning <fanningpj@apache.org>2023-03-25 00:47:15 +0000
commit9e53a4f7c28aeb9ae19cfcdc9e2e2a2c3060f82f (patch)
tree805a709d177a6929778a2a9fbcb80426184d6639 /poi
parent98f5f248add8fb57936e4bcc00a9592287577d3f (diff)
downloadpoi-9e53a4f7c28aeb9ae19cfcdc9e2e2a2c3060f82f.tar.gz
poi-9e53a4f7c28aeb9ae19cfcdc9e2e2a2c3060f82f.zip
don't share the skip bytes buffer
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1908700 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java13
1 files changed, 3 insertions, 10 deletions
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index 9988c429cc..a69f1b052f 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -46,7 +46,6 @@ public final class IOUtils {
* The default buffer size to use for the skip() methods.
*/
private static final int SKIP_BUFFER_SIZE = 2048;
- private static byte[] SKIP_BYTE_BUFFER;
/**
* The current set global allocation limit override,
@@ -520,18 +519,12 @@ public final class IOUtils {
if (toSkip == 0) {
return 0L;
}
- /*
- * N.B. no need to synchronize this because: - we don't care if the buffer is created multiple times (the data
- * is ignored) - we always use the same size buffer, so if it is recreated it will still be OK (if the buffer
- * size were variable, we would need to synch. to ensure some other thread did not create a smaller one)
- */
- if (SKIP_BYTE_BUFFER == null) {
- SKIP_BYTE_BUFFER = new byte[SKIP_BUFFER_SIZE];
- }
+ // use dedicated buffer to avoid having other threads possibly access the bytes in a shared byte array
+ final byte[] skipBuffer = new byte[SKIP_BUFFER_SIZE];
long remain = toSkip;
while (remain > 0) {
// See https://issues.apache.org/jira/browse/IO-203 for why we use read() rather than delegating to skip()
- final long n = input.read(SKIP_BYTE_BUFFER, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
+ final long n = input.read(skipBuffer, 0, (int) Math.min(remain, SKIP_BUFFER_SIZE));
if (n < 0) { // EOF
break;
}