Skip to content
File

Blob: patches/v8/0001-Allow-manually-setting-ValueDeserializer-format-vers.patch

3.0 KB
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Alex Robinson <arobinson@cloudflare.com>
3Date: Wed, 2 Mar 2022 15:58:04 -0600
4Subject: Allow manually setting ValueDeserializer format version
5 
6For many years, V8's serialization version didn't change. In the meantime,
7we accidentally stored data that was missing a version header. This patch
8allows us to start using a header while still being able to correctly
9interpret our existing stored data that was missing a header, using code
10like:
11 
12 auto maybeHeader = deserializer.ReadHeader(isolate->GetCurrentContext());
13 KJ_ASSERT(maybeHeader.IsNothing() || maybeHeader.FromJust());
14 if (deserializer.GetWireFormatVersion() == 0) {
15 deserializer.SetWireFormatVersion(13);
16 }
17 auto maybeValue = deserializer.ReadValue(isolate->GetCurrentContext());
18 
19Signed-off-by: James M Snell <jsnell@cloudflare.com>
20 
21diff --git a/include/v8-value-serializer.h b/include/v8-value-serializer.h
22index 0cb3e045bc46ec732956318b980e749d1847d06d..40ad805c7970cc9379e69f046205836dbd760373 100644
23--- a/include/v8-value-serializer.h
24+++ b/include/v8-value-serializer.h
25@@ -293,6 +293,13 @@ class V8_EXPORT ValueDeserializer {
26 */
27 uint32_t GetWireFormatVersion() const;
28
29+ /**
30+ * Sets the underlying wire format version. Should only be used if there's no
31+ * header specifying the wire format version but you're confident you know
32+ * what version was used to serialize the data.
33+ */
34+ void SetWireFormatVersion(uint32_t version);
35+
36 /**
37 * Reads raw data in various common formats to the buffer.
38 * Note that integer types are read in base-128 varint format, not with a
39diff --git a/src/api/api.cc b/src/api/api.cc
40index 32fc059d6d2375fd87cb2f263a5846444fd9d0d1..e98a1d272b663f26e41313f10b99cd564793c5f8 100644
41--- a/src/api/api.cc
42+++ b/src/api/api.cc
43@@ -3706,6 +3706,10 @@ uint32_t ValueDeserializer::GetWireFormatVersion() const {
44 return private_->deserializer.GetWireFormatVersion();
45 }
46
47+void ValueDeserializer::SetWireFormatVersion(uint32_t version) {
48+ private_->deserializer.SetWireFormatVersion(version);
49+}
50+
51 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
52 PrepareForExecutionScope api_scope{context,
53 RCCId::kAPI_ValueDeserializer_ReadValue};
54diff --git a/src/objects/value-serializer.h b/src/objects/value-serializer.h
55index 43dc34d6189d7332e019db758760eb5c71a9fe99..b84dcc77d4060d13c389b4afed101847c85998da 100644
56--- a/src/objects/value-serializer.h
57+++ b/src/objects/value-serializer.h
58@@ -221,6 +221,13 @@ class ValueDeserializer {
59 */
60 uint32_t GetWireFormatVersion() const { return version_; }
61
62+ /*
63+ * Sets the underlying wire format version. Should only be used if there's no
64+ * header specifying the wire format version but you're confident you know
65+ * what version was used to serialize the data.
66+ */
67+ void SetWireFormatVersion(uint32_t version) { version_ = version; }
68+
69 /*
70 * Deserializes a V8 object from the buffer.
71 */