Skip to content

Commit 5b0e543

Browse files
Fix cord handling in DynamicMessage and oneofs. (#18373)
* Fix cord handling in DynamicMessage and oneofs. This fixes a memory corruption vulnerability for anyone using cord with dynamically built descriptor pools. * Silence expected ubsan failures from absl::Cord --------- Co-authored-by: Mike Kruskal <[email protected]>
1 parent 421fc16 commit 5b0e543

Some content is hidden

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

51 files changed

+672
-527
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1
2222
# Workaround for the fact that Bazel links with $CC, not $CXX
2323
# https://github.com/bazelbuild/bazel/issues/11122#issuecomment-613746748
2424
build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
25+
# Abseil passes nullptr to memcmp with 0 size
26+
build:ubsan --copt=-fno-sanitize=nonnull-attribute
2527

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

ci/common.bazelrc

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

3133
# Workaround Bazel 7 remote cache issues.
3234
# See https://github.com/bazelbuild/bazel/issues/20161

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;
@@ -402,47 +401,6 @@ public void computeTagSize() {
402401
assertThat(CodedOutputStream.computeTagSize((1 << 30) + 1)).isEqualTo(1);
403402
}
404403

405-
/** Tests writing a whole message with every field type. */
406-
@Test
407-
public void testWriteWholeMessage() throws Exception {
408-
final byte[] expectedBytes = TestUtil.getGoldenMessage().toByteArray();
409-
TestAllTypes message = TestUtil.getAllSet();
410-
411-
for (OutputType outputType : OutputType.values()) {
412-
Coder coder = outputType.newCoder(message.getSerializedSize());
413-
message.writeTo(coder.stream());
414-
coder.stream().flush();
415-
byte[] rawBytes = coder.toByteArray();
416-
assertEqualBytes(outputType, expectedBytes, rawBytes);
417-
}
418-
419-
// Try different block sizes.
420-
for (int blockSize = 1; blockSize < 256; blockSize *= 2) {
421-
Coder coder = OutputType.STREAM.newCoder(blockSize);
422-
message.writeTo(coder.stream());
423-
coder.stream().flush();
424-
assertEqualBytes(OutputType.STREAM, expectedBytes, coder.toByteArray());
425-
}
426-
}
427-
428-
/**
429-
* Tests writing a whole message with every packed field type. Ensures the wire format of packed
430-
* fields is compatible with C++.
431-
*/
432-
@Test
433-
public void testWriteWholePackedFieldsMessage() throws Exception {
434-
byte[] expectedBytes = TestUtil.getGoldenPackedFieldsMessage().toByteArray();
435-
TestPackedTypes message = TestUtil.getPackedSet();
436-
437-
for (OutputType outputType : OutputType.values()) {
438-
Coder coder = outputType.newCoder(message.getSerializedSize());
439-
message.writeTo(coder.stream());
440-
coder.stream().flush();
441-
byte[] rawBytes = coder.toByteArray();
442-
assertEqualBytes(outputType, expectedBytes, rawBytes);
443-
}
444-
}
445-
446404
/**
447405
* Test writing a message containing a negative enum value. This used to fail because the size was
448406
* not properly computed as a sign-extended varint.

0 commit comments

Comments
 (0)