Corrupted pointer in node::fs::ReadFileUtf8(const FunctionCallbackInfo<Value>& args) when args[0] is a string.
An internal Node.js binding for reading a file as UTF-8 text mishandles a buffer when the path argument is a string, so a pointer in the file-system request structure is overwritten and memory is leaked on every call. Repeated calls cause unbounded memory growth that could lead to a denial of service.
Originally disclosed on HackerOne
- Triaged in 3 days
- Fixed in 36 days
- Disclosed after 37 days
Summary by the program
In Node.js, the ReadFileUtf8 internal binding leaks memory due to a corrupted pointer in uv_fs_s.file: a UTF-16 path buffer is allocated but subsequently overwritten when the file descriptor is set. This results in an unrecoverable memory leak on every call. Repeated use can cause unbounded memory growth, leading to a denial of service.
Impact:
- This vulnerability affects APIs relying on
ReadFileUtf8on Node.js release lines: v20 and v22.
What the report shows
The target is the Node.js runtime, specifically the internal binding ReadFileUtf8, which is exposed to JavaScript as node::fs::ReadFileUtf8(const FunctionCallbackInfo<Value>& args). The report concerns the case where args[0] is a string, that is, a path passed as a JavaScript string.
According to the program's summary, the binding leaks memory because of a corrupted pointer in uv_fs_s.file. A UTF-16 path buffer is allocated, but it is subsequently overwritten when the file descriptor is set. The result is an unrecoverable memory leak on every call. Repeated use can cause unbounded memory growth, leading to a denial of service.
The report states that the affected APIs are those relying on ReadFileUtf8 on the Node.js release lines v20 and v22. The platform records the report as low severity with a CVSS score of 3.7, classified as generic memory corruption, against the https://github.com/nodejs/node asset. No bounty amount is given.
Root cause
The mistake the report points to is a lifetime and ownership problem around a path buffer. A UTF-16 buffer is allocated to hold the path, and the same structure, uv_fs_s, also carries the file descriptor in its file field. When the descriptor is set, the pointer that should still refer to the allocated path buffer is overwritten. The allocation is then no longer reachable, so it can never be freed.
Because the overwrite happens on every call, the leak is not a one-off: each invocation of ReadFileUtf8 with a string argument loses another buffer. The report describes the leak as unrecoverable, meaning the memory is lost for the lifetime of the process rather than being reclaimed later.
Impact
The impact described is a denial of service through unbounded memory growth. Any code path that reaches ReadFileUtf8 repeatedly with a string path will keep consuming memory until the process is exhausted. The report limits the affected release lines to v20 and v22. It does not describe remote exploitation, privilege escalation or data disclosure.
How this kind of bug works
Memory leaks of this shape come from a mismatch between allocation and ownership. A buffer is allocated in one place, and a pointer to it is stored in a structure that is later reused for a different purpose. If the code overwrites the pointer without freeing the buffer first, or without keeping a second reference, the allocation becomes orphaned. Garbage collection does not help here, because the buffer lives outside the JavaScript heap, in native code, where only explicit frees reclaim it.
The bug class is dangerous when the leaking operation is reachable from untrusted input and can be triggered many times. A single leak of a few hundred bytes is harmless; a leak on every request in a long-running server is a slow denial of service. Defences are mostly structural: clear ownership rules for native buffers, single points of allocation and free, and the use of smart pointers or RAII wrappers so that a buffer cannot outlive its only reference. Fuzzing with leak detection and long-running stress tests catch this class well, because the symptom only appears after many iterations.
How to test for it
- Identify native bindings or extensions that accept a path or buffer from JavaScript and hand it to an operating system call.
- Exercise the same call in a loop, with a string argument, and watch the process's resident memory over time.
- Compare the growth against a control loop that does not call the binding, to rule out normal allocator behaviour.
- Use a leak checker or heap profiler on the native side, not just the JavaScript heap, since the lost buffer will not appear there.
A positive result looks like memory that grows roughly linearly with the number of calls and does not fall back after garbage collection. Common false positives are allocator caching, lazy freeing and growth caused by the JavaScript objects around the call rather than the native buffer. Repeating the test with a fixed number of iterations and measuring the delta per call separates a real leak from noise.
How it is fixed
Hunting notes
This class tends to hide in the boundary between a managed runtime and native code: file system wrappers, path handling, buffer conversions between encodings, and any binding that stores a pointer in a struct shared with other state. Recon signals include native addons, internal bindings exposed to script, and code that converts strings to UTF-16 or other wide encodings before a system call.
What happened, in plain words
Node.js is a program that lets you run JavaScript outside a web browser, for example on a server. Many websites and tools are built on it. This report is about a bug inside Node.js itself, in a piece of code called ReadFileUtf8, which is the internal machinery Node.js uses when JavaScript asks it to read a file whose path is given as text.
The report concerns the case where args[0] is a string, that is, a path passed as a JavaScript string. Think of args[0] as the first item in the list of things the caller handed over: here, the file path.
According to the program's summary, this code leaks memory. Memory is the working space a program uses while it runs. A leak means the program asks the computer for a chunk of memory, then loses track of it, so it can never hand it back. The summary explains the cause: a pointer is corrupted. A pointer is simply a note that says where a chunk of memory lives. The code allocates a buffer (a reserved block of memory) to hold the file path in UTF-16, an encoding that stores text using two bytes per character. But that pointer is then overwritten when the file descriptor is set. A file descriptor is the number the operating system gives back when a file is opened, so the program can refer to it later. The same structure, uv_fs_s, holds both the path pointer and the file descriptor in its file field, and writing the descriptor there wipes out the note pointing at the path buffer.
The result is an unrecoverable memory leak on every call. Unrecoverable here means the memory is lost for as long as the program runs, not reclaimed later. Repeated use can cause unbounded memory growth, leading to a denial of service. A denial of service means the program, or the machine it runs on, becomes so overloaded that it can no longer do its job.
The report states that the affected APIs are those relying on ReadFileUtf8 on the Node.js release lines v20 and v22. An API is the set of functions a program offers to other code. The platform records the report as low severity with a CVSS score of 3.7. CVSS is a standard scoring system for how serious a security flaw is, running from 0 to 10. The weakness is classified as generic memory corruption, and the asset is the Node.js source code at https://github.com/nodejs/node. No bounty amount is given.
Root cause
The mistake the report points to is a lifetime and ownership problem around a path buffer. A buffer is allocated to hold the path, and the same structure, uv_fs_s, also carries the file descriptor in its file field. When the descriptor is set, the pointer that should still refer to the allocated path buffer is overwritten. The allocation is then no longer reachable, so it can never be freed.
A useful comparison is a cloakroom. You hand in your coat and get a ticket with a number on it. If someone writes a different number on your ticket, the cloakroom still holds your coat, but nobody can ever ask for it again. The coat is not destroyed; it is simply stranded. That is what happens to the path buffer.
Because the overwrite happens on every call, the leak is not a one-off: each invocation of ReadFileUtf8 with a string argument loses another buffer. The report describes the leak as unrecoverable, meaning the memory is lost for the lifetime of the process rather than being reclaimed later.
Impact
The impact described is a denial of service through unbounded memory growth. Any code path that reaches ReadFileUtf8 repeatedly with a string path will keep consuming memory until the process is exhausted. The report limits the affected release lines to v20 and v22. It does not describe remote exploitation, privilege escalation or data disclosure.
In general, how this kind of bug works
Memory leaks of this shape come from a mismatch between allocation and ownership. A buffer is allocated in one place, and a pointer to it is stored in a structure that is later reused for a different purpose. If the code overwrites the pointer without freeing the buffer first, or without keeping a second reference, the allocation becomes orphaned. Garbage collection does not help here. Garbage collection is the automatic cleanup that languages like JavaScript perform on their own objects. But this buffer lives outside the JavaScript heap, in native code, where only explicit frees reclaim it. The heap is the pool of memory a program draws from for its objects.
The bug class is dangerous when the leaking operation is reachable from untrusted input and can be triggered many times. A single leak of a few hundred bytes is harmless; a leak on every request in a long-running server is a slow denial of service. Defences are mostly structural: clear ownership rules for native buffers, single points of allocation and free, and the use of smart pointers or RAII wrappers so that a buffer cannot outlive its only reference. RAII is a programming habit where a resource is tied to an object, so it is released automatically when that object goes away. Fuzzing with leak detection and long-running stress tests catch this class well, because the symptom only appears after many iterations. Fuzzing means feeding a program large amounts of generated input to see what breaks.
In general, how to test for it
- Identify native bindings or extensions that accept a path or buffer from JavaScript and hand it to an operating system call. A binding is the glue that lets JavaScript call code written in another language.
- Exercise the same call in a loop, with a string argument, and watch the process's resident memory over time. Resident memory is the part of memory the process currently holds in the computer's RAM.
- Compare the growth against a control loop that does not call the binding, to rule out normal allocator behaviour. The allocator is the part of the system that hands out memory.
- Use a leak checker or heap profiler on the native side, not just the JavaScript heap, since the lost buffer will not appear there. A heap profiler is a tool that shows what is using memory.
A positive result looks like memory that grows roughly linearly with the number of calls and does not fall back after garbage collection. Common false positives are allocator caching, lazy freeing and growth caused by the JavaScript objects around the call rather than the native buffer. Repeating the test with a fixed number of iterations and measuring the delta per call separates a real leak from noise.
In general, how it is fixed
In general, hunting notes
This class tends to hide in the boundary between a managed runtime and native code: file system wrappers, path handling, buffer conversions between encodings, and any binding that stores a pointer in a struct shared with other state. A struct is a bundle of related fields kept together. Recon signals include native addons, internal bindings exposed to script, and code that converts strings to UTF-16 or other wide encodings before a system call.
Glossary
- Node.js: a program that runs JavaScript outside a browser, often on servers.
- Binding: glue code that lets JavaScript call functions written in another language.
ReadFileUtf8: the internal Node.js function that reads a file whose path is given as text.args[0]: the first argument passed to a function, here the file path.- String: a piece of text in a program.
- Pointer: a note recording where a chunk of memory lives.
- Buffer: a reserved block of memory used to hold data.
- UTF-16: a way of storing text that uses two bytes per character.
- File descriptor: the number the operating system returns when a file is opened, used to refer to it later.
uv_fs_s: the structure that holds file system state, including the path pointer and the file descriptor in itsfilefield.- Struct: a bundle of related fields kept together.
- Memory leak: memory a program reserves and then loses track of, so it cannot be reused.
- Unrecoverable: lost for as long as the program runs, not reclaimed later.
- Denial of service: overloading a program or machine so it can no longer do its job.
- API: the set of functions a program offers to other code.
- CVSS: a standard 0 to 10 score for how serious a security flaw is.
- Memory corruption: damage to memory contents that makes a program behave unpredictably.
- Heap: the pool of memory a program draws from for its objects.
- Garbage collection: automatic cleanup of a language's own objects.
- RAII: a programming habit where a resource is released automatically when the object holding it goes away.
- Fuzzing: feeding a program large amounts of generated input to see what breaks.
- Resident memory: the part of memory a process currently holds in RAM.
- Allocator: the part of the system that hands out memory.
- Heap profiler: a tool that shows what is using memory.
- Regression test: a check kept in a project so an old bug cannot quietly return.