aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-08-15 01:56:37 -0700
committerGravatar GitHub <noreply@github.com> 2023-08-15 01:56:37 -0700
commit1a6a52314f88946e66ac0f36d00d624ec1a5296f (patch)
treec43b3eb518d51e97e21cfbfae4808941c4771df7 /src
parent47450ed12ccfe1d76ca527ea95f602e6ba089dce (diff)
downloadbun-1a6a52314f88946e66ac0f36d00d624ec1a5296f.tar.gz
bun-1a6a52314f88946e66ac0f36d00d624ec1a5296f.tar.zst
bun-1a6a52314f88946e66ac0f36d00d624ec1a5296f.zip
fix importing too long of strings (#4155)
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/javascript.zig22
-rw-r--r--src/fs.zig5
2 files changed, 24 insertions, 3 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index e7ed3e0ab..3e5ac799d 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -1438,6 +1438,28 @@ pub const VirtualMachine = struct {
is_esm: bool,
comptime is_a_file_path: bool,
) void {
+ if (is_a_file_path and specifier.length() > comptime @as(u32, @intFromFloat(@trunc(@as(f64, @floatFromInt(bun.MAX_PATH_BYTES)) * 1.5)))) {
+ const specifier_utf8 = specifier.toUTF8(bun.default_allocator);
+ defer specifier_utf8.deinit();
+ const source_utf8 = source.toUTF8(bun.default_allocator);
+ defer source_utf8.deinit();
+ const printed = ResolveMessage.fmt(
+ bun.default_allocator,
+ specifier_utf8.slice(),
+ source_utf8.slice(),
+ error.NameTooLong,
+ ) catch @panic("Out of Memory");
+ const msg = logger.Msg{
+ .data = logger.rangeData(
+ null,
+ logger.Range.None,
+ printed,
+ ),
+ };
+ res.* = ErrorableString.err(error.NameTooLong, ResolveMessage.create(global, VirtualMachine.get().allocator, msg, source.utf8()).asVoid());
+ return;
+ }
+
var result = ResolveFunctionResult{ .path = "", .result = null };
var jsc_vm = VirtualMachine.get();
const specifier_utf8 = specifier.toUTF8(bun.default_allocator);
diff --git a/src/fs.zig b/src/fs.zig
index fd06006f5..51d3fb4b7 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -255,9 +255,8 @@ pub const FileSystem = struct {
}
pub fn get(entry: *const DirEntry, _query: string) ?Entry.Lookup {
- if (_query.len == 0) return null;
- var scratch_lookup_buffer: [256]u8 = undefined;
- std.debug.assert(scratch_lookup_buffer.len >= _query.len);
+ if (_query.len == 0 or _query.len > bun.MAX_PATH_BYTES) return null;
+ var scratch_lookup_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
const query = strings.copyLowercaseIfNeeded(_query, &scratch_lookup_buffer);
const result = entry.data.get(query) orelse return null;