summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-js/UniFFIPointer.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:33 +0000
commit086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch)
treea4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /toolkit/components/uniffi-js/UniFFIPointer.cpp
parentAdding debian version 124.0.1-1. (diff)
downloadfirefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz
firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/uniffi-js/UniFFIPointer.cpp')
-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) {