From 84e81cfa6c540b885bdb2412c94029c952bcf63c Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Tue, 3 Dec 2024 12:32:14 -0800 Subject: [PATCH] Make Java-lite reject unmatched end-group tag. This brings it into conformance with our spec and other languages. PiperOrigin-RevId: 702432195 --- conformance/failure_list_java_lite.txt | 4 ---- .../src/main/java/com/google/protobuf/UnknownFieldSchema.java | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/conformance/failure_list_java_lite.txt b/conformance/failure_list_java_lite.txt index 39a0f21c5c6b3..1494114f0877d 100644 --- a/conformance/failure_list_java_lite.txt +++ b/conformance/failure_list_java_lite.txt @@ -6,7 +6,3 @@ Required.*.ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE # Should have failed to parse, but didn't. Required.*.ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE # Should have failed to parse, but didn't. -Required.*.ProtobufInput.UnmatchedEndGroup # Should have failed to parse, but didn't. -Required.*.ProtobufInput.UnmatchedEndGroupUnknown # Should have failed to parse, but didn't. -Required.*.ProtobufInput.UnmatchedEndGroupWithData # Should have failed to parse, but didn't. -Required.*.ProtobufInput.UnmatchedEndGroupWrongType # Should have failed to parse, but didn't. diff --git a/java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java b/java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java index 80602b16359aa..5e2683dc6ccd1 100644 --- a/java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java +++ b/java/core/src/main/java/com/google/protobuf/UnknownFieldSchema.java @@ -93,6 +93,9 @@ final boolean mergeOneFieldFrom(B unknownFields, Reader reader, int currentDepth addGroup(unknownFields, fieldNumber, toImmutable(subFields)); return true; case WireFormat.WIRETYPE_END_GROUP: + if (currentDepth == 0) { + throw InvalidProtocolBufferException.invalidEndTag(); + } return false; default: throw InvalidProtocolBufferException.invalidWireType();