diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/components/uniffi-js | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-upstream/125.0.1.tar.xz firefox-upstream/125.0.1.zip |
Adding upstream version 125.0.1.upstream/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.cpp | 38 |
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) { |