From b3f83e6fe1d1957da40e4eb3eb97db4f666b0177 Mon Sep 17 00:00:00 2001 From: yizhenqiang Date: Sun, 16 Apr 2023 20:56:49 +0800 Subject: [PATCH] Avoid `long` overflow in `RedisSubscription.potentiallyReadMore()` #2383 Instead of incrementing the demand plus one, we now deduct one from the available data size (which is an int). --- src/main/java/io/lettuce/core/RedisPublisher.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/lettuce/core/RedisPublisher.java b/src/main/java/io/lettuce/core/RedisPublisher.java index 125d5d289a..c26dd3c59a 100644 --- a/src/main/java/io/lettuce/core/RedisPublisher.java +++ b/src/main/java/io/lettuce/core/RedisPublisher.java @@ -408,7 +408,11 @@ void checkOnDataAvailable() { void potentiallyReadMore() { - if ((getDemand() + 1) > data.size()) { + /* + * getDemand() maybe is Long.MAX_VALUE,because MonoNext.NextSubscriber#request(long n) inner use the Long.MAX_VALUE, + * so maybe "getDemand() + 1" will be overflow,we use "getDemand() > data.size() - 1" replace the "(getDemand() + 1) > data.size()" + */ + if (getDemand() > data.size() - 1) { state().readData(this); } }