mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8322141: SequenceInputStream.transferTo should not return as soon as Long.MAX_VALUE bytes have been transferred
Reviewed-by: vsitnikov, bpb, jpai
This commit is contained in:
parent
e0bad5153b
commit
2d609557ff
2 changed files with 50 additions and 2 deletions
|
@ -242,11 +242,14 @@ public class SequenceInputStream extends InputStream {
|
|||
if (getClass() == SequenceInputStream.class) {
|
||||
long transferred = 0;
|
||||
while (in != null) {
|
||||
long numTransferred = in.transferTo(out);
|
||||
// increment the total transferred byte count
|
||||
// only if we haven't already reached the Long.MAX_VALUE
|
||||
if (transferred < Long.MAX_VALUE) {
|
||||
try {
|
||||
transferred = Math.addExact(transferred, in.transferTo(out));
|
||||
transferred = Math.addExact(transferred, numTransferred);
|
||||
} catch (ArithmeticException ignore) {
|
||||
return Long.MAX_VALUE;
|
||||
transferred = Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
nextStream();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue