aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/collect
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2018-03-23 12:14:19 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-23 12:16:01 -0700
commitbc891adec58a6f5b9c3740f5b0131fe00d5e507f (patch)
tree5b8a340a356f8506b02a6d5d53149c354cbbf543 /src/main/java/com/google/devtools/build/lib/collect
parent10798099687faad9edd9a3b9e4e46b03cedfaad7 (diff)
Re-enable aliasing of CodedInputStream during deserialization, removed as part of primary codepath somewhere around https://github.com/bazelbuild/bazel/commit/bde43ec8a96a62b8fbf67ad60d5154cf121647d9 (and killed entirely in unknown commit.
Force copying of a ByteString read from CodedInputStream in NestedSetCodec and persisted, since otherwise we might hang onto the entire buffer indefinitely. PiperOrigin-RevId: 190256337
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/collect')
-rw-r--r--src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java
index b8d8a2207e..ba170820b3 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetCodec.java
@@ -177,7 +177,11 @@ public class NestedSetCodec<T> implements ObjectCodec<NestedSet<T>> {
// will point at the same object in memory instead of duplicating them. Unfortunately, we had
// to do the work of deserializing the member that we will now throw away, in order to ensure
// that the pointer in the codedIn buffer was incremented appropriately.
- Object oldValue = digestToChild.putIfAbsent(digest, result);
+ Object oldValue =
+ digestToChild.putIfAbsent(
+ // Copy the ByteString to avoid keeping the full buffer from codedIn alive due to
+ // aliasing.
+ ByteString.copyFrom(digest.asReadOnlyByteBuffer()), result);
return oldValue == null ? result : oldValue;
}