Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chrome IndexedDB] Fix header processing #1814

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions ee/indexeddb/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
// We read the version followed by 0x6f -- we have completed reading the header.
return version, nil
}
default:
// Padding -- ignore
continue
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion ee/indexeddb/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Loading