This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 3ad7b5fa9 Limit couchjs line length to JS string length limit
3ad7b5fa9 is described below

commit 3ad7b5fa9fe830e321a8197ac5e9961427d9acb8
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Mon Nov 16 14:10:55 2026 -0500

    Limit couchjs line length to JS string length limit
    
    Lines longer than that could segfault so we'd rather handle it as an 
explicit
    error.
---
 src/couch_quickjs/c_src/couchjs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/couch_quickjs/c_src/couchjs.c 
b/src/couch_quickjs/c_src/couchjs.c
index 420f5f41d..e4c07916b 100644
--- a/src/couch_quickjs/c_src/couchjs.c
+++ b/src/couch_quickjs/c_src/couchjs.c
@@ -19,6 +19,8 @@
 
 #define DEFAULT_STACK_SIZE (64L * 1024L * 1024L)
 #define BUF_SIZE 1024
+// Longest line which still fits in a JS string
+#define MAX_LINE_LEN ((1 << 30) - 1)
 
 #define USAGE "couchjs [-V|-M memorylimit|-h] <script.js>\n"
 
@@ -294,8 +296,11 @@ static JSValue js_readline(JSContext* cx, JSValueConst 
this_val, int argc, JSVal
     if(!line) {
       BAIL("Could not allocate line buffer for list sub-command");
     }
-    int len;
+    ssize_t len;
     if ((len = linein(&line, &linemax)) != -1) {
+      if (len > MAX_LINE_LEN) {
+        BAIL("list linein() line too long");
+      }
       if (line[len - 1] != '\n') {
         BAIL("list linein() didn't end in newline");
       }
@@ -473,9 +478,12 @@ int main(int argc, const char* argv[])
       BAIL("Could not allocate line buffer");
     }
 
-    int len;
+    ssize_t len;
     bool do_continue = true;
     while (do_continue && (len = linein(&line, &linemax)) != -1) {
+      if (len > MAX_LINE_LEN) {
+        BAIL("linein() line too long");
+      }
       if (line[len - 1] != '\n') {
         BAIL("linein() didn't end in newline");
       }

Reply via email to