aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-21 14:30:17 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-21 14:30:17 -0700
commiteb3765ef93d73ef4d0f9e7b5b80336b640e1e28d (patch)
treec2da26330976f1185b6abe668945cd404c59b2db
parentb33f20d51b728137bf38b69b82fd481c4a0f6fc8 (diff)
downloadbun-eb3765ef93d73ef4d0f9e7b5b80336b640e1e28d.tar.gz
bun-eb3765ef93d73ef4d0f9e7b5b80336b640e1e28d.tar.zst
bun-eb3765ef93d73ef4d0f9e7b5b80336b640e1e28d.zip
[internal] Add a 0 byte to EOF read files as a precaution
-rw-r--r--src/fs.zig6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/fs.zig b/src/fs.zig
index daa512dcb..d38d6c2b3 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -1047,7 +1047,7 @@ pub const FileSystem = struct {
if (use_shared_buffer) {
shared_buffer.reset();
var offset: u64 = 0;
- try shared_buffer.growBy(size);
+ try shared_buffer.growBy(size + 1);
shared_buffer.list.expandToCapacity();
// if you press save on a large file we might not read all the
@@ -1087,6 +1087,10 @@ pub const FileSystem = struct {
}
break;
}
+
+ if (shared_buffer.list.capacity > file_contents.len) {
+ file_contents.ptr[file_contents.len] = 0;
+ }
} else {
// We use pread to ensure if the file handle was open, it doesn't seek from the last position
var buf = try allocator.alloc(u8, size + 1);