From 34b4755a4a768895b1abf569e5a52f1fd4d1aea5 Mon Sep 17 00:00:00 2001 From: Joey Stanford Date: Sun, 19 Jul 2026 08:50:27 -0600 Subject: [PATCH] fix: stop readString at embedded NUL bytes Some companion frames append trailing fields after a string that used to be frame-remainder. Decoding past an embedded NUL produces garbage for callers that still use readString(). Truncate at the first NUL when present. Carried as a pnpm patch in Colorado-Mesh/mesh-client. --- src/buffer_reader.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/buffer_reader.js b/src/buffer_reader.js index 9142fbc..2f8cf2d 100644 --- a/src/buffer_reader.js +++ b/src/buffer_reader.js @@ -24,7 +24,10 @@ class BufferReader { } readString() { - return new TextDecoder().decode(this.readRemainingBytes()); + const bytes = this.readRemainingBytes(); + const nullIdx = bytes.indexOf(0); + const slice = nullIdx >= 0 ? bytes.subarray(0, nullIdx) : bytes; + return new TextDecoder().decode(slice); } readCString(maxLength) {