From af1ecc03531461900c1c9b8499aa64f5900bca27 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 9 May 2024 15:16:16 -0700 Subject: [PATCH] Add a check to ensure that the byte limit is not negative. PiperOrigin-RevId: 632284538 --- .../src/main/java/com/google/protobuf/CodedInputStream.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java index 81da417783..6fb96afa4b 100644 --- a/java/core/src/main/java/com/google/protobuf/CodedInputStream.java +++ b/java/core/src/main/java/com/google/protobuf/CodedInputStream.java @@ -2690,6 +2690,9 @@ public abstract class CodedInputStream { throw InvalidProtocolBufferException.negativeSize(); } byteLimit += totalBytesRetired + pos; + if (byteLimit < 0) { + throw InvalidProtocolBufferException.parseFailure(); + } final int oldLimit = currentLimit; if (byteLimit > oldLimit) { throw InvalidProtocolBufferException.truncatedMessage();