0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-21 15:04:33 -05:00

fix: Check for null pointer returned by ValueSerializer::Release (#1599)

* Check for null ptr during release

* Add to test

* Reorder
This commit is contained in:
Nathan Whitaker 2024-08-29 16:10:06 -07:00 committed by GitHub
parent 909f6d3afa
commit eb29f6bd8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 8 deletions

View file

@ -536,14 +536,17 @@ impl<'a> ValueSerializer<'a> {
&mut ptr,
&mut size,
);
Vec::from_raw_parts(
ptr,
size,
self
.value_serializer_heap
.buffer_size
.swap(0, std::sync::atomic::Ordering::Relaxed),
)
let capacity = self
.value_serializer_heap
.buffer_size
.swap(0, std::sync::atomic::Ordering::Relaxed);
if ptr.is_null() {
return Vec::new();
}
assert!(size <= capacity);
// SAFETY: ptr is non-null, was allocated by us in `v8__ValueSerializer__Delegate__ReallocateBufferMemory`, and
// the capacity is correctly updated during reallocation. Size is asserted to be valid above.
Vec::from_raw_parts(ptr, size, capacity)
}
}

View file

@ -8070,6 +8070,7 @@ fn value_serializer_and_deserializer() {
value_serializer.write_double(55.44);
value_serializer.write_uint32(22);
buffer = value_serializer.release();
assert_eq!(value_serializer.release(), Vec::new());
}
let mut double: f64 = 0.0;