Skip to content

Bun.file(path).json() is missing a max length check for UTF-16 strings #19276

Open
@capaj

Description

@capaj

What version of Bun is running?

1.2.11-canary.53+83a2a6496

What platform is your computer?

Linux 6.8.0-58-generic x86_64 x86_6

What steps can reproduce the bug?

have a 4GB json file and run

const file = await Bun.file('4GB.json').json()

What is the expected behavior?

Either the file gets opened or

RangeError [ERR_FS_FILE_TOO_LARGE]: File size (4240424690) is greater than 2 GiB
    at FSReqCallback.readFileAfterStat [as oncomplete] (node:fs:322:11) {
  code: 'ERR_FS_FILE_TOO_LARGE'
}

should get thrown like in node.js

What do you see instead?

it throws:

[1]    3602275 IOT instruction (core dumped)  bun monster/parse.ts

Additional information

I know I can use streaming, but I have a huge invalid json, so parsing is problematic too. I have plenty of memory(128 GB) so loading up 4 GB JSON would ideally work

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun:fs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions