From fa643c19dd957ee69a1629b0a20cc87780219cc1 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Wed, 31 Jul 2024 15:34:07 -0400 Subject: [PATCH 1/2] Fix header processing --- ee/indexeddb/values.go | 22 ++++++++++++++++------ ee/indexeddb/values_test.go | 6 +++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ee/indexeddb/values.go b/ee/indexeddb/values.go index 2127aed82..ad5f86dfd 100644 --- a/ee/indexeddb/values.go +++ b/ee/indexeddb/values.go @@ -69,8 +69,9 @@ func DeserializeChrome(ctx context.Context, slogger *slog.Logger, row map[string } // readHeader reads through the header bytes at the start of `srcReader`. -// It parses the version, if found. It stops as soon as it reaches the first -// object reference. +// It parses the version, if found. The header always ends with the byte +// 0xff (tokenVersion), followed by the version (a varint), followed by 0x6f (tokenObjectBegin) +// -- we stop reading the header at this point. func readHeader(srcReader *bytes.Reader) (uint64, error) { var version uint64 for { @@ -84,16 +85,25 @@ func readHeader(srcReader *bytes.Reader) (uint64, error) { switch nextByte { case tokenVersion: + // Read the version first. It is fine to overwrite version if we saw the version token + // before -- the last instance of the version token is the correct one. version, err = binary.ReadUvarint(srcReader) if err != nil { return 0, fmt.Errorf("decoding uint32: %w", err) } - case tokenObjectBegin: - // Done reading header - return version, nil + + // Next, determine whether this is the 0xff token at the end of the header + peekByte, err := srcReader.ReadByte() + if err != nil { + return 0, fmt.Errorf("peeking at next byte after version tag: %w", err) + } + + if peekByte == tokenObjectBegin { + // Our last two bytes are 0xff 0x6f -- we have completed reading the header. + return version, nil + } default: // Padding -- ignore - continue } } } diff --git a/ee/indexeddb/values_test.go b/ee/indexeddb/values_test.go index be50a43d0..468ed5ca4 100644 --- a/ee/indexeddb/values_test.go +++ b/ee/indexeddb/values_test.go @@ -19,6 +19,8 @@ func Test_deserializeIndexeddbValue(t *testing.T) { 0x00, // padding, ignore 0x00, // padding, ignore 0x00, // padding, ignore + 0xff, // version tag (indicates end of header) + 0x0f, // version // object 0x6f, // object begin 0x22, // string tag @@ -49,9 +51,11 @@ func Test_deserializeIndexeddbValue_InvalidType(t *testing.T) { 0x00, // padding, ignore 0x00, // padding, ignore 0x00, // padding, ignore + 0xff, // version tag (indicates end of header) + 0x0f, // version // object 0x6f, // object begin - 0xff, // version tag -- invalid data! + 0x54, // boolean true tag -- invalid data! 0x7b, // object end 0x00, // properties_written } From 03662649a00199162f47eaf3d80e55dcc07af6e9 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Wed, 31 Jul 2024 15:37:17 -0400 Subject: [PATCH 2/2] Fix comment --- ee/indexeddb/values.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/indexeddb/values.go b/ee/indexeddb/values.go index ad5f86dfd..f619cfff0 100644 --- a/ee/indexeddb/values.go +++ b/ee/indexeddb/values.go @@ -99,7 +99,7 @@ func readHeader(srcReader *bytes.Reader) (uint64, error) { } if peekByte == tokenObjectBegin { - // Our last two bytes are 0xff 0x6f -- we have completed reading the header. + // We read the version followed by 0x6f -- we have completed reading the header. return version, nil } default: