Force a copy when saving the NSData that came from another.
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index 3be20b6..cc1a650 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -2027,7 +2027,12 @@
[newInput release];
} else {
GPBUnknownFieldSet *unknownFields = GetOrMakeUnknownFields(self);
- [unknownFields mergeMessageSetMessage:typeId data:rawBytes];
+ // rawBytes was created via a NoCopy, so it can be reusing a
+ // subrange of another NSData that might go out of scope as things
+ // unwind, so a copy is needed to ensure what is saved in the
+ // unknown fields stays valid.
+ NSData *cloned = [NSData dataWithData:rawBytes];
+ [unknownFields mergeMessageSetMessage:typeId data:cloned];
}
}
}