[vlc-commits] [Git][videolan/vlc][master] 5 commits: wasm: emjsfile: fix out of bound size read

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Mar 11 21:04:07 UTC 2024



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
0769dfad by Alaric Senat at 2024-03-11T20:45:01+00:00
wasm: emjsfile: fix out of bound size read

The condition was flawed. This is supposed to check that the read size
does not go out of bound.

- - - - -
f9134055 by Alaric Senat at 2024-03-11T20:45:01+00:00
wasm: emjsfile: remove unused promise parameter

- - - - -
2733cbc9 by Mehdi Sabwat at 2024-03-11T20:45:01+00:00
wasm: emjsfile: fix sys leak

Avoid allocating the context too early so the ID parsing failure doesn't
leak.

- - - - -
153da806 by Mehdi Sabwat at 2024-03-11T20:45:01+00:00
wasm: emjsfile: align file size value

Align the file size value directly in the context structure to avoid
extra variable declaration.

Co-Authored-By: Alaric Senat <alaric at videolabs.io>

- - - - -
04381d69 by Mehdi Sabwat at 2024-03-11T20:45:01+00:00
wasm: emjsfile: fix pthread worker access

Emscripten simplified the access to the worker object.

- - - - -


1 changed file:

- modules/access/emjsfile.c


Changes:

=====================================
modules/access/emjsfile.c
=====================================
@@ -28,12 +28,14 @@
 #include <vlc_access.h>
 #include <vlc_threads.h>
 #include <stdalign.h>
+#include <assert.h>
+
 #include <emscripten.h>
 
 typedef struct
 {
     uint64_t offset;
-    uint64_t js_file_size;
+    uint64_t alignas(8) js_file_size;
 } access_sys_t;
 
 static ssize_t Read (stream_t *p_access, void *buffer, size_t size) {
@@ -44,9 +46,8 @@ static ssize_t Read (stream_t *p_access, void *buffer, size_t size) {
 
     if (offset >= js_file_size)
         return 0;
-    if (size > offset + js_file_size) {
+    if (size + offset > js_file_size)
         size = js_file_size - offset;
-    }
     EM_ASM({
         const offset = $0;
         const buffer = $1;
@@ -71,8 +72,8 @@ static int get_js_file_size(stream_t *p_access, uint64_t *value) {
       to avoid RangeError on BigUint64 view creation,
       the start offset (value) must be a multiple of 8.
     */
-    alignas(8) uint64_t file_size = 0;
-    int ret = (EM_ASM_INT({
+    assert(((uintptr_t)value % 8) == 0);
+    return (EM_ASM_INT({
         try {
             var v = new BigUint64Array(wasmMemory.buffer, $0, 1);
             v[0] = BigInt(Module.vlcAccess[$1].worker_js_file.size);
@@ -82,9 +83,7 @@ static int get_js_file_size(stream_t *p_access, uint64_t *value) {
             console.error("get_js_file_size error: " + error);
             return 1;
         }
-    }, &file_size, p_access) == 0) ? VLC_SUCCESS: VLC_EGENERIC;
-    *value = file_size;
-    return ret;
+    }, value, p_access) == 0) ? VLC_SUCCESS: VLC_EGENERIC;
 }
 
 static int Control( stream_t *p_access, int i_query, va_list args )
@@ -157,9 +156,9 @@ EM_ASYNC_JS(int, init_js_file, (stream_t *p_access, long id), {
         self.addEventListener('message', handleFileResult);
     });
     let timer = undefined;
-    let timeout = new Promise(function (resolve, reject) {
-            timer = setTimeout(resolve, 1000, 'timeout')
-        });
+    let timeout = new Promise((resolve) => {
+        timer = setTimeout(resolve, 1000, 'timeout');
+    });
     let promises = [p, timeout];
     /* id must be unique */
     self.postMessage({ cmd: "customCmd", type: "requestFile", id: id});
@@ -208,7 +207,7 @@ static int EmFileOpen( vlc_object_t *p_this ) {
     */
     MAIN_THREAD_EM_ASM({
         const thread_id = $0;
-        let w = Module.PThread.pthreads[thread_id].worker;
+        let w = Module.PThread.pthreads[thread_id];
         function handleFileRequest(e) {
             const msg = e.data;
             if (msg.type === "requestFile") {
@@ -248,11 +247,6 @@ static int EmFileOpen( vlc_object_t *p_this ) {
         w.addEventListener('message', handleFileRequest);
     }, pthread_self());
 
-    access_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof (*p_sys));
-    if (unlikely(p_sys == NULL)) {
-        return VLC_ENOMEM;
-    }
-
     char *endPtr;
     long id = strtol(p_access->psz_location, &endPtr, 10);
     if ((endPtr == p_access->psz_location) || (*endPtr != '\0')) {
@@ -260,6 +254,10 @@ static int EmFileOpen( vlc_object_t *p_this ) {
         return VLC_EGENERIC;
     }
 
+    access_sys_t *p_sys = vlc_obj_malloc(p_this, sizeof (*p_sys));
+    if (unlikely(p_sys == NULL))
+        return VLC_ENOMEM;
+
     /*
       Request the file from the main thread.
       If it was not selected, it will return an error.



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/652fa4e5a17d7311eec3cc3c03edb77aaf4836db...04381d694c9198c419bdb97c32e769a4cff90271

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/652fa4e5a17d7311eec3cc3c03edb77aaf4836db...04381d694c9198c419bdb97c32e769a4cff90271
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list