Skip to content

Commit e673479

Browse files
Fix cord handling in DynamicMessage and oneofs. (#18375)
* Fix cord handling in DynamicMessage and oneofs. This fixes a memory corruption vulnerability for anyone using cord with dynamically built descriptor pools. * Update staleness. Run using Bazel 6.3.2 docker image * Silence expected ubsan failures from absl::Cord --------- Co-authored-by: Mike Kruskal <[email protected]>
1 parent 8a60b65 commit e673479

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+785
-478
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ build:ubsan --copt=-DUNDEFINED_SANITIZER=1
2626
# Workaround for the fact that Bazel links with $CC, not $CXX
2727
# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748
2828
build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
29+
# Abseil passes nullptr to memcmp with 0 size
30+
build:ubsan --copt=-fno-sanitize=nonnull-attribute
2931

3032
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
3133
# https://github.com/protocolbuffers/protobuf/issues/14313

ci/common.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ build:ubsan --copt=-DUNDEFINED_SANITIZER=1
3434
# Workaround for the fact that Bazel links with $CC, not $CXX
3535
# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748
3636
build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
37+
# Abseil passes nullptr to memcmp with 0 size
38+
build:ubsan --copt=-fno-sanitize=nonnull-attribute

java/core/src/test/java/com/google/protobuf/CodedOutputStreamTest.java

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.google.protobuf.CodedOutputStream.OutOfSpaceException;
1414
import protobuf_unittest.UnittestProto.SparseEnumMessage;
1515
import protobuf_unittest.UnittestProto.TestAllTypes;
16-
import protobuf_unittest.UnittestProto.TestPackedTypes;
1716
import protobuf_unittest.UnittestProto.TestSparseEnum;
1817
import java.io.ByteArrayInputStream;
1918
import java.io.ByteArrayOutputStream;
@@ -327,47 +326,6 @@ public void testEncodeZigZag() throws Exception {
327326
.isEqualTo(-75123905439571256L);
328327
}
329328

330-
/** Tests writing a whole message with every field type. */
331-
@Test
332-
public void testWriteWholeMessage() throws Exception {
333-
final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray();
334-
TestAllTypes message = TestUtil.getAllSet();
335-
336-
for (OutputType outputType : OutputType.values()) {
337-
Coder coder = outputType.newCoder(message.getSerializedSize());
338-
message.writeTo(coder.stream());
339-
coder.stream().flush();
340-
byte[] rawBytes = coder.toByteArray();
341-
assertEqualBytes(outputType, expectedBytes, rawBytes);
342-
}
343-
344-
// Try different block sizes.
345-
for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
346-
Coder coder = OutputType.STREAM.newCoder(blockSize);
347-
message.writeTo(coder.stream());
348-
coder.stream().flush();
349-
assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray());
350-
}
351-
}
352-
353-
/**
354-
* Tests writing a whole message with every packed field type. Ensures the wire format of packed
355-
* fields is compatible with C++.
356-
*/
357-
@Test
358-
public void testWriteWholePackedFieldsMessage() throws Exception {
359-
byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray();
360-
TestPackedTypes message = TestUtil.getPackedSet();
361-
362-
for (OutputType outputType : OutputType.values()) {
363-
Coder coder = outputType.newCoder(message.getSerializedSize());
364-
message.writeTo(coder.stream());
365-
coder.stream().flush();
366-
byte[] rawBytes = coder.toByteArray();
367-
assertEqualBytes(outputType, expectedBytes, rawBytes);
368-
}
369-
}
370-
371329
/**
372330
* Test writing a message containing a negative enum value. This used to fail because the size was
373331
* not properly computed as a sign-extended varint.

0 commit comments

Comments
 (0)