Bug 1440195 For timestamps that are absolute, specify a null context pointer r?baku draft
authorTom Ritter <tom@mozilla.com>
Wed, 28 Feb 2018 15:37:26 -0600
changeset 767471 9f69e3802148b0af56b99c68ce91ecc8f3003496
parent 767470 c1611ee0df8cbd4e63e02ce515184f809851ec5a
child 767472 8535014c39560943dc3018fffac3b30f90d99d94
push id102611
push userbmo:tom@mozilla.com
push dateWed, 14 Mar 2018 17:48:37 +0000
reviewersbaku
bugs1440195
milestone60.0a1
Bug 1440195 For timestamps that are absolute, specify a null context pointer r?baku Note that by not using the same context pointer for all timestamps within a single 'communication group' (that is, all things that can communication to each other in JavaScript), it's possible to observe time going backwards. Imagine comparing performance.timeOrigin + performance.now() < new File([], "").lastModified In theory this should always be true. However, if performance.now() was jittered up (using one context pointer, because it is a relative timestamp) and File was jittered down (using a null context pointer, because it is an absolute timestamp) then this may evaluate to False. I think this is okay. MozReview-Commit-ID: BfgbmGS8XdD
dom/file/BaseBlobImpl.cpp
dom/file/MultipartBlobImpl.cpp
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- a/dom/file/BaseBlobImpl.cpp
+++ b/dom/file/BaseBlobImpl.cpp
@@ -59,17 +59,18 @@ BaseBlobImpl::GetType(nsAString& aType)
   aType = mContentType;
 }
 
 int64_t
 BaseBlobImpl::GetLastModified(ErrorResult& aRv)
 {
   MOZ_ASSERT(mIsFile, "Should only be called on files");
   if (IsDateUnknown()) {
-    mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now());
+    mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now(), 0);
+    // mLastModificationDate is an absolute timestamp so we supply a zero context mix-in
   }
 
   return mLastModificationDate / PR_USEC_PER_MSEC;
 }
 
 void
 BaseBlobImpl::SetLastModified(int64_t aLastModified)
 {
--- a/dom/file/MultipartBlobImpl.cpp
+++ b/dom/file/MultipartBlobImpl.cpp
@@ -264,17 +264,18 @@ MultipartBlobImpl::SetLengthAndModifiedD
   mLength = totalLength;
 
   if (mIsFile) {
     // We cannot use PR_Now() because bug 493756 and, for this reason:
     //   var x = new Date(); var f = new File(...);
     //   x.getTime() < f.dateModified.getTime()
     // could fail.
     mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(
-      lastModifiedSet ? lastModified * PR_USEC_PER_MSEC : JS_Now());
+      lastModifiedSet ? lastModified * PR_USEC_PER_MSEC : JS_Now(), 0);
+    // mLastModificationDate is an absolute timestamp so we supply a zero context mix-in
   }
 }
 
 void
 MultipartBlobImpl::GetMozFullPathInternal(nsAString& aFilename,
                                           ErrorResult& aRv) const
 {
   if (!mIsFromNsIFile || mBlobImpls.Length() == 0) {
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -552,17 +552,17 @@ nsRFPService::ReduceTimePrecisionAsUSecs
 /* static */
 double
 nsRFPService::ReduceTimePrecisionAsUSecsWrapper(double aTime)
 {
   return nsRFPService::ReduceTimePrecisionImpl(
     aTime,
     MicroSeconds,
     TimerResolution(),
-    0,
+    0, /* For absolute timestamps (all the JS engine does), supply zero context mixin */
     TimerPrecisionType::All);
 }
 
 /* static */
 double
 nsRFPService::ReduceTimePrecisionAsMSecs(
   double aTime,
   int64_t aContextMixin,