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

fix array buffer (de)serialization #322

Merged
merged 1 commit into from
Aug 14, 2024
Merged
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
10 changes: 5 additions & 5 deletions shared/helpers/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ alt::MValueByteArray V8Helpers::V8ToRawBytes(v8::Local<v8::Value> val)
v8::ValueSerializer serializer(isolate, &delegate);
delegate.SetSerializer(&serializer);

serializer.WriteHeader();

// Write the magic bytes to the buffer
serializer.WriteRawBytes(magicBytes, sizeof(magicBytes));

serializer.WriteHeader();

// Write the serialized value to the buffer
bool result;
if(!serializer.WriteValue(ctx, val).To(&result) || !result) return alt::MValueByteArray();
Expand All @@ -547,14 +547,14 @@ v8::MaybeLocal<v8::Value> V8Helpers::RawBytesToV8(alt::MValueByteArrayConst rawB
v8::ValueDeserializer deserializer(isolate, data, size, &delegate);
delegate.SetDeserializer(&deserializer);

bool headerValid;
if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal<v8::Value>();

// Check for magic bytes
uint8_t* magicBytesPtr;
if(!deserializer.ReadRawBytes(sizeof(magicBytes), (const void**)&magicBytesPtr)) return v8::MaybeLocal<v8::Value>();
if(memcmp(magicBytesPtr, magicBytes, sizeof(magicBytes)) != 0) return v8::MaybeLocal<v8::Value>();

bool headerValid;
if(!deserializer.ReadHeader(ctx).To(&headerValid) || !headerValid) return v8::MaybeLocal<v8::Value>();

// Deserialize the value
v8::MaybeLocal<v8::Value> result = deserializer.ReadValue(ctx);

Expand Down
Loading