changeset 2571:fe90cd2cad82

Fixed handling of detached buffer for typed arrays.
author Dmitry Volyntsev <xeioex@nginx.com>
date Thu, 12 Jun 2025 17:20:07 -0700
parents 7ade97e7d376
children 97d668817758
files src/njs_typed_array.c src/njs_value.c
diffstat 2 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/njs_typed_array.c	Thu Jun 12 15:34:39 2025 -0700
+++ b/src/njs_typed_array.c	Thu Jun 12 17:20:07 2025 -0700
@@ -655,6 +655,11 @@
         return ret;
     }
 
+    buffer = njs_typed_array_buffer(array);
+    if (njs_slow_path(njs_is_detached_buffer(buffer))) {
+        return NJS_OK;
+    }
+
     buffer = njs_typed_array_writable(vm, array);
     if (njs_slow_path(buffer == NULL)) {
         return NJS_ERROR;
--- a/src/njs_value.c	Thu Jun 12 15:34:39 2025 -0700
+++ b/src/njs_value.c	Thu Jun 12 17:20:07 2025 -0700
@@ -1019,8 +1019,7 @@
             tarray = njs_typed_array(value);
 
             if (njs_slow_path(njs_is_detached_buffer(tarray->buffer))) {
-                njs_type_error(vm, "detached buffer");
-                return NJS_ERROR;
+                goto not_found;
             }
 
             if (njs_slow_path(index >= njs_typed_array_length(tarray))) {
@@ -1109,6 +1108,7 @@
         break;
 
     case NJS_DECLINED:
+not_found:
         njs_set_undefined(retval);
 
         return NJS_DECLINED;