Bug 1641598 - Fix defect in Key::LengthOfEncodedBinary. r=ttung, a=RyanVM
authorSimon Giesecke <sgiesecke@mozilla.com>
Mon, 29 Jun 2020 14:36:51 +0000
changeset 601893 5007d36153abdbfce831be777885fa083c66de3e
parent 601892 002beecf7a10859d138d17ef7e436f90f9632c0b
child 601894 a24cfb80b10eafb3c5d534f5a85be792c19d8afe
push id13342
push userryanvm@gmail.com
push dateThu, 02 Jul 2020 16:51:46 +0000
treeherdermozilla-beta@54b80be511d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttung, RyanVM
bugs1641598
milestone79.0
Bug 1641598 - Fix defect in Key::LengthOfEncodedBinary. r=ttung, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D78696
dom/indexedDB/Key.cpp
--- a/dom/indexedDB/Key.cpp
+++ b/dom/indexedDB/Key.cpp
@@ -123,18 +123,28 @@ IDBResult<void, IDBSpecialValue::Invalid
 
 // |aPos| should point to the type indicator.
 // The returned length doesn't include the type indicator
 // or the terminator.
 // static
 uint32_t Key::LengthOfEncodedBinary(const EncodedDataType* aPos,
                                     const EncodedDataType* aEnd) {
   MOZ_ASSERT(*aPos % Key::eMaxType == Key::eBinary, "Don't call me!");
-  const EncodedDataType* encodedSectionEnd;
-  return CalcDecodedStringySize<uint8_t>(aPos + 1, aEnd, &encodedSectionEnd);
+
+  const auto* iter = aPos + 1;
+  for (; iter < aEnd && *iter != eTerminator; ++iter) {
+    if (*iter & 0x80) {
+      ++iter;
+      // XXX if iter == aEnd now, we got a bad enconding, should we report that
+      // also in non-debug builds?
+      MOZ_ASSERT(iter < aEnd);
+    }
+  }
+
+  return iter - aPos - 1;
 }
 
 IDBResult<void, IDBSpecialValue::Invalid> Key::ToLocaleAwareKey(
     Key& aTarget, const nsCString& aLocale, ErrorResult& aRv) const {
   if (IsUnset()) {
     aTarget.Unset();
     return Ok();
   }