summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:14:29 +0000
commitfbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch)
tree4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /toolkit/components/uniffi-js
parentReleasing progress-linux version 124.0.1-1~progress7.99u1. (diff)
downloadfirefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz
firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-js')
-rw-r--r--toolkit/components/uniffi-js/UniFFIPointer.cpp38
1 files changed, 21 insertions, 17 deletions
diff --git a/toolkit/components/uniffi-js/UniFFIPointer.cpp b/toolkit/components/uniffi-js/UniFFIPointer.cpp
index 87a1d5fe69..c3a1eba93d 100644
--- a/toolkit/components/uniffi-js/UniFFIPointer.cpp
+++ b/toolkit/components/uniffi-js/UniFFIPointer.cpp
@@ -40,12 +40,12 @@ already_AddRefed<UniFFIPointer> UniFFIPointer::Read(
MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info,
("[UniFFI] Reading Pointer from buffer"));
+ CheckedUint32 end = CheckedUint32(aPosition) + 8;
uint8_t data_ptr[8];
- if (!aArrayBuff.CopyDataTo(
- data_ptr,
- [aPosition](size_t aLength) -> Maybe<std::pair<size_t, size_t>> {
- CheckedUint32 end = aPosition + 8;
- if (!end.isValid() || end.value() > aLength) {
+ if (!end.isValid() ||
+ !aArrayBuff.CopyDataTo(
+ data_ptr, [&](size_t aLength) -> Maybe<std::pair<size_t, size_t>> {
+ if (end.value() > aLength) {
return Nothing();
}
return Some(std::make_pair(aPosition, 8));
@@ -72,18 +72,22 @@ void UniFFIPointer::Write(const ArrayBuffer& aArrayBuff, uint32_t aPosition,
MOZ_LOG(sUniFFIPointerLogger, LogLevel::Info,
("[UniFFI] Writing Pointer to buffer"));
- aArrayBuff.ProcessData([&](const Span<uint8_t>& aData,
- JS::AutoCheckCannotGC&&) {
- CheckedUint32 end = aPosition + 8;
- if (!end.isValid() || end.value() > aData.Length()) {
- aError.ThrowRangeError("position is out of range");
- return;
- }
- // in Rust and Read(), a u64 is read as BigEndian and then converted to
- // a pointer we do the reverse here
- const auto& data_ptr = aData.Subspan(aPosition, 8);
- mozilla::BigEndian::writeUint64(data_ptr.Elements(), (uint64_t)GetPtr());
- });
+ CheckedUint32 end = CheckedUint32(aPosition) + 8;
+ if (!end.isValid() || !aArrayBuff.ProcessData([&](const Span<uint8_t>& aData,
+ JS::AutoCheckCannotGC&&) {
+ if (end.value() > aData.Length()) {
+ return false;
+ }
+ // in Rust and Read(), a u64 is read as BigEndian and then converted to
+ // a pointer we do the reverse here
+ const auto& data_ptr = aData.Subspan(aPosition, 8);
+ mozilla::BigEndian::writeUint64(data_ptr.Elements(),
+ (uint64_t)GetPtr());
+ return true;
+ })) {
+ aError.ThrowRangeError("position is out of range");
+ return;
+ }
}
UniFFIPointer::UniFFIPointer(void* aPtr, const UniFFIPointerType* aType) {