Bug 1439450 - Ignore has_first_value() check in ProtocolParser. r=francois
authorDimi Lee <dlee@mozilla.com>
Tue, 16 Oct 2018 10:36:01 +0000
changeset 489789 37d138b1e58b9c45ee3baef530bb133597b14eb3
parent 489788 4fa33210cbc490a1dc353e2288b507138de81772
child 489790 89308a0efe91b73daa395ca4af36727e5c151b4b
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersfrancois
bugs1439450
milestone64.0a1
Bug 1439450 - Ignore has_first_value() check in ProtocolParser. r=francois Sometimes the protocol buffer data (RiceEncodingData) sent by Google's Safe Browsing server has the following properties: 1. |has_first_value| is false 2. |num_entries| > 0 In this case, we can still parse the data and apply partial update correctly by assuming that the first value is equal to 0. Differential Revision: https://phabricator.services.mozilla.com/D6393
toolkit/components/url-classifier/ProtocolParser.cpp
xpcom/base/ErrorList.py
--- a/toolkit/components/url-classifier/ProtocolParser.cpp
+++ b/toolkit/components/url-classifier/ProtocolParser.cpp
@@ -999,28 +999,29 @@ ProtocolParserProtobuf::ProcessRawRemova
 
   return NS_OK;
 }
 
 static nsresult
 DoRiceDeltaDecode(const RiceDeltaEncoding& aEncoding,
                   nsTArray<uint32_t>& aDecoded)
 {
-  if (!aEncoding.has_first_value()) {
-    PARSER_LOG(("The encoding info is incomplete."));
-    return NS_ERROR_UC_PARSER_MISSING_PARAM;
-  }
   if (aEncoding.num_entries() > 0 &&
       (!aEncoding.has_rice_parameter() || !aEncoding.has_encoded_data())) {
     PARSER_LOG(("Rice parameter or encoded data is missing."));
     return NS_ERROR_UC_PARSER_MISSING_PARAM;
+  } else if (aEncoding.num_entries() == 0 && !aEncoding.has_first_value()) {
+    PARSER_LOG(("Missing first_value for an single-integer Rice encoding."));
+    return NS_ERROR_UC_PARSER_MISSING_VALUE;
   }
 
+  auto first_value = aEncoding.has_first_value() ? aEncoding.first_value() : 0;
+
   PARSER_LOG(("* Encoding info:"));
-  PARSER_LOG(("  - First value: %" PRId64, aEncoding.first_value()));
+  PARSER_LOG(("  - First value: %" PRId64, first_value));
   PARSER_LOG(("  - Num of entries: %d", aEncoding.num_entries()));
   PARSER_LOG(("  - Rice parameter: %d", aEncoding.rice_parameter()));
 
   // Set up the input buffer. Note that the bits should be read
   // from LSB to MSB so that we in-place reverse the bits before
   // feeding to the decoder.
   auto encoded = const_cast<RiceDeltaEncoding&>(aEncoding).mutable_encoded_data();
   RiceDeltaDecoder decoder((uint8_t*)encoded->c_str(), encoded->size());
@@ -1029,17 +1030,17 @@ DoRiceDeltaDecode(const RiceDeltaEncodin
   // the output buffer.
   if (!aDecoded.SetLength(aEncoding.num_entries() + 1, mozilla::fallible)) {
     NS_WARNING("Not enough memory to decode the RiceDelta input.");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // Decode!
   bool rv = decoder.Decode(aEncoding.rice_parameter(),
-                           aEncoding.first_value(), // first value.
+                           first_value,
                            aEncoding.num_entries(), // # of entries (first value not included).
                            &aDecoded[0]);
 
   NS_ENSURE_TRUE(rv, NS_ERROR_UC_PARSER_DECODE_FAILURE);
 
   return NS_OK;
 }
 
--- a/xpcom/base/ErrorList.py
+++ b/xpcom/base/ErrorList.py
@@ -1088,16 +1088,17 @@ with modules["URL_CLASSIFIER"]:
     errors["NS_ERROR_UC_UPDATE_BUILD_PREFIX_FAILURE"] = FAILURE(9)
     errors["NS_ERROR_UC_UPDATE_FAIL_TO_WRITE_DISK"] = FAILURE(10)
     errors["NS_ERROR_UC_UPDATE_UNEXPECTED_VERSION"] = FAILURE(11)
 
     # Specific errors while parsing pver2/pver4 responses
     errors["NS_ERROR_UC_PARSER_MISSING_PARAM"] = FAILURE(12)
     errors["NS_ERROR_UC_PARSER_DECODE_FAILURE"] = FAILURE(13)
     errors["NS_ERROR_UC_PARSER_UNKNOWN_THREAT"] = FAILURE(14)
+    errors["NS_ERROR_UC_PARSER_MISSING_VALUE"] = FAILURE(15)
 
 
 # =======================================================================
 # 43: NS_ERROR_MODULE_ERRORRESULT
 # =======================================================================
 with modules["ERRORRESULT"]:
     # Represents a JS Value being thrown as an exception.
     errors["NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION"] = FAILURE(1)