From 5543882f488f12087211b1bf88e2284508d691a7 Mon Sep 17 00:00:00 2001 From: Shen Liu Date: Mon, 28 Nov 2022 15:53:32 +0800 Subject: [PATCH] [fix][offload] Fix numerical overflow bug while reading data from tiered storage (#18595) Co-authored-by: druidliu (cherry picked from commit 5c34e846561efc26ba7fc8b64383fefad4f1072a) --- .../offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java index e3fc68ab7e218..c5fda387c73f6 100644 --- a/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java +++ b/tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreBackedInputStreamImpl.java @@ -144,6 +144,7 @@ public void close() { @Override public int available() throws IOException { - return (int)(objectLen - cursor) + buffer.readableBytes(); + long available = objectLen - cursor + buffer.readableBytes(); + return available > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) available; } }