oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.15k stars 2.77k forks source link

FileSystemRouter causes crash on Windows when handling URL pathnames containing spaces (%20) #12187

Open qhariN opened 4 months ago

qhariN commented 4 months ago

How can we reproduce the crash?

When using Bun.FileSystemRouter on Windows, the server crashes if the pathname of the URL contains spaces (encoded as %20). The issue seems to occur during the router.match(url.pathname) call.

const router = new Bun.FileSystemRouter({
  style: 'nextjs',
  dir: './'
})

const server = Bun.serve({
  fetch(req) {
    const url = new URL(req.url)
    const matchedRoute = router.match(url.pathname)
    return new Response(matchedRoute)
  }
})

Relevant log output

panic(main thread): @memcpy arguments alias
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.1.17/wa1bb66bbaAiggBm/ylPs84lP2wr22C_A0eNpzyE3NTS6oVEgsSi/NTc0rKVZIzMlMLAYAae8I7A

Stack Trace (bun.report)

Bun v1.1.17 (bb66bba) on windows x86_64 [AutoCommand]

panic: @memcpy arguments alias

Jarred-Sumner commented 4 months ago

Debug build stack trace:

panic(main thread): @memcpy arguments alias
/Users/jarred/Code/bun/src/deps/zig/lib/std/io/fixed_buffer_stream.zig:66:57: 0x10335da6f in write (bun-debug)
            @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
                                                        ^
/Users/jarred/Code/bun/src/deps/zig/lib/std/io.zig:360:27: 0x10335d6c3 in typeErasedWriteFn (bun-debug)
            return writeFn(ptr.*, bytes);
                          ^
/Users/jarred/Code/bun/src/deps/zig/lib/std/io/Writer.zig:13:24: 0x10335d4bf in write (bun-debug)
    return self.writeFn(self.context, bytes);
                       ^
/Users/jarred/Code/bun/src/deps/zig/lib/std/io/Writer.zig:19:32: 0x102e9bd2f in writeAll (bun-debug)
        index += try self.write(bytes[index..]);
                               ^
/Users/jarred/Code/bun/src/deps/zig/lib/std/io.zig:320:50: 0x103d8cd4b in decodeFaultTolerant__anon_111022 (bun-debug)
            return @errorCast(self.any().writeAll(bytes));
                                                 ^
/Users/jarred/Code/bun/src/http/url_path.zig:77:96: 0x103d8d47f in parse (bun-debug)
        decoded_pathname = possibly_encoded_pathname[0..try PercentEncoding.decodeFaultTolerant(@TypeOf(writer), writer, clone, &needs_redirect, true)];
                                                                                               ^
/Users/jarred/Code/bun/src/bun.js/api/filesystem_router.zig:305:39: 0x103d8ffbf in match (bun-debug)
        const url_path = URLPath.parse(path.slice()) catch |err| {