[tor-commits] [Git][tpo/applications/tor-browser][base-browser-102.12.0esr-12.0-1] Bug 1832832 - protect encoder accesses in Java callbacks. r=media-playback-reviewers, alwu a=pascalc

richard (@richard) git at gitlab.torproject.org
Tue Jun 6 16:35:53 UTC 2023



richard pushed to branch base-browser-102.12.0esr-12.0-1 at The Tor Project / Applications / Tor Browser


Commits:
0c25c6c7 by John Lin at 2023-06-06T16:35:31+00:00
Bug 1832832 - protect encoder accesses in Java callbacks. r=media-playback-reviewers,alwu a=pascalc

Differential Revision: https://phabricator.services.mozilla.com/D178564
- - - - -


2 changed files:

- dom/media/platforms/android/AndroidDataEncoder.cpp
- dom/media/platforms/android/AndroidDataEncoder.h


Changes:

=====================================
dom/media/platforms/android/AndroidDataEncoder.cpp
=====================================
@@ -494,7 +494,10 @@ void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleInput(
 template <typename ConfigType>
 void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleOutput(
     java::Sample::Param aSample, java::SampleBuffer::Param aBuffer) {
-  mEncoder->ProcessOutput(std::move(aSample), std::move(aBuffer));
+  MutexAutoLock lock(mMutex);
+  if (mEncoder) {
+    mEncoder->ProcessOutput(std::move(aSample), std::move(aBuffer));
+  }
 }
 
 template <typename ConfigType>
@@ -504,7 +507,10 @@ void AndroidDataEncoder<ConfigType>::CallbacksSupport::
 template <typename ConfigType>
 void AndroidDataEncoder<ConfigType>::CallbacksSupport::HandleError(
     const MediaResult& aError) {
-  mEncoder->Error(aError);
+  MutexAutoLock lock(mMutex);
+  if (mEncoder) {
+    mEncoder->Error(aError);
+  }
 }
 
 // Force compiler to generate code.


=====================================
dom/media/platforms/android/AndroidDataEncoder.h
=====================================
@@ -13,6 +13,7 @@
 
 #include "mozilla/Maybe.h"
 #include "mozilla/Monitor.h"
+#include "mozilla/Mutex.h"
 
 namespace mozilla {
 
@@ -36,7 +37,15 @@ class AndroidDataEncoder final : public MediaDataEncoder {
   class CallbacksSupport final : public JavaCallbacksSupport {
    public:
     explicit CallbacksSupport(AndroidDataEncoder* aEncoder)
-        : mEncoder(aEncoder) {}
+        : mMutex("AndroidDataEncoder::CallbacksSupport") {
+      MutexAutoLock lock(mMutex);
+      mEncoder = aEncoder;
+    }
+
+    ~CallbacksSupport() {
+      MutexAutoLock lock(mMutex);
+      mEncoder = nullptr;
+    }
 
     void HandleInput(int64_t aTimestamp, bool aProcessed) override;
     void HandleOutput(java::Sample::Param aSample,
@@ -46,7 +55,8 @@ class AndroidDataEncoder final : public MediaDataEncoder {
     void HandleError(const MediaResult& aError) override;
 
    private:
-    AndroidDataEncoder* mEncoder;
+    Mutex mMutex;
+    AndroidDataEncoder* mEncoder MOZ_GUARDED_BY(mMutex);
   };
   friend class CallbacksSupport;
 



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/0c25c6c77942c31c04fe090500288e4a652788d6

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/0c25c6c77942c31c04fe090500288e4a652788d6
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20230606/057f864b/attachment-0001.htm>


More information about the tor-commits mailing list