Bug 1637339: Only validate constrained values when element read succeeded. r=jrmuizel
authorBob Owen <bobowencode@gmail.com>
Fri, 22 May 2020 18:22:07 +0000
changeset 531702 a2bde621288c12c60a129b1f5eeb1dce5a544c20
parent 531701 151f9f0eaadaedf9d8c105ffe04b8fefd719549a
child 531703 8fbcd4668bae62cbba94dfa1657b0d8cce8aa225
push id37442
push userncsoregi@mozilla.com
push dateSat, 23 May 2020 09:21:24 +0000
treeherdermozilla-central@bbcc193fe0f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1637339
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1637339: Only validate constrained values when element read succeeded. r=jrmuizel Differential Revision: https://phabricator.services.mozilla.com/D75570
gfx/2d/RecordedEventImpl.h
gfx/2d/RecordingTypes.h
--- a/gfx/2d/RecordedEventImpl.h
+++ b/gfx/2d/RecordedEventImpl.h
@@ -1606,16 +1606,20 @@ void RecordedEvent::ReadPatternData(S& a
       ReadElement(aStream, *reinterpret_cast<ConicGradientPatternStorage*>(
                                &aPattern.mStorage));
       return;
     }
     case PatternType::SURFACE: {
       SurfacePatternStorage* sps =
           reinterpret_cast<SurfacePatternStorage*>(&aPattern.mStorage);
       ReadElement(aStream, *sps);
+      if (!aStream.good()) {
+        return;
+      }
+
       if (sps->mExtend < ExtendMode::CLAMP ||
           sps->mExtend > ExtendMode::REFLECT) {
         gfxDevCrash(LogReason::InvalidConstrainedValueRead)
             << "Invalid ExtendMode read: value: " << int(sps->mExtend)
             << ", min: " << int(ExtendMode::CLAMP)
             << ", max: " << int(ExtendMode::REFLECT);
         aStream.SetIsBad();
       }
@@ -1749,16 +1753,20 @@ void RecordedEvent::ReadStrokeOptions(S&
   aStrokeOptions.mDashPattern = &mDashPatternStorage.front();
   aStream.read((char*)aStrokeOptions.mDashPattern,
                sizeof(Float) * aStrokeOptions.mDashLength);
 }
 
 template <class S>
 static void ReadDrawOptions(S& aStream, DrawOptions& aDrawOptions) {
   ReadElement(aStream, aDrawOptions);
+  if (!aStream.good()) {
+    return;
+  }
+
   if (aDrawOptions.mAntialiasMode < AntialiasMode::NONE ||
       aDrawOptions.mAntialiasMode > AntialiasMode::DEFAULT) {
     gfxDevCrash(LogReason::InvalidConstrainedValueRead)
         << "Invalid AntialiasMode read: value: "
         << int(aDrawOptions.mAntialiasMode)
         << ", min: " << int(AntialiasMode::NONE)
         << ", max: " << int(AntialiasMode::DEFAULT);
     aStream.SetIsBad();
@@ -1774,16 +1782,20 @@ static void ReadDrawOptions(S& aStream, 
     aStream.SetIsBad();
   }
 }
 
 template <class S>
 static void ReadDrawSurfaceOptions(S& aStream,
                                    DrawSurfaceOptions& aDrawSurfaceOptions) {
   ReadElement(aStream, aDrawSurfaceOptions);
+  if (!aStream.good()) {
+    return;
+  }
+
   if (aDrawSurfaceOptions.mSamplingFilter < SamplingFilter::GOOD ||
       aDrawSurfaceOptions.mSamplingFilter >= SamplingFilter::SENTINEL) {
     gfxDevCrash(LogReason::InvalidConstrainedValueRead)
         << "Invalid SamplingFilter read: value: "
         << int(aDrawSurfaceOptions.mSamplingFilter)
         << ", min: " << int(SamplingFilter::GOOD)
         << ", sentinel: " << int(SamplingFilter::SENTINEL);
     aStream.SetIsBad();
--- a/gfx/2d/RecordingTypes.h
+++ b/gfx/2d/RecordingTypes.h
@@ -44,16 +44,20 @@ template <class S, class T,
           typename = typename std::enable_if<!std::is_enum<T>::value>::type>
 void ReadElement(S& aStream, T& aElement) {
   ElementStreamFormat<S, T>::Read(aStream, aElement);
 }
 template <class S, class T>
 void ReadElementConstrained(S& aStream, T& aElement, const T& aMinValue,
                             const T& aMaxValue) {
   ElementStreamFormat<S, T>::Read(aStream, aElement);
+  if (!aStream.good()) {
+    return;
+  }
+
   if (aElement < aMinValue || aElement > aMaxValue) {
     gfxDevCrash(LogReason::InvalidConstrainedValueRead)
         << "Invalid constrained value read: value: " << int(aElement)
         << ", min: " << int(aMinValue) << ", max: " << int(aMaxValue);
     aStream.SetIsBad();
   }
 }
 template <class S, class T>