GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing github.com — Don't loop forever in AbstractDiskHttpData when the file is short by Marti2203 · Pull Request #17973 · netty/netty Conversation
Contributor
Motivation:
Modification:
Result:
Reproduction on 4.2 (5776ebc) on Linux, where sysfs files report a length of 4096: DiskAttribute attr = new DiskAttribute("y"); attr.setContent(new File("/sys/kernel/mm/transparent_hugepage/enabled")); // length() == 4096, 23 bytes readable here attr.get(); // never returns; the thread is still RUNNABLE in FileDispatcherImpl.read0 after 3 s With this change This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually. 🤖 Generated with Claude Code
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsMotivation: AbstractDiskHttpData.readFrom(File), which get(), getByteBuf() and getString() use, allocates an array of File.length() bytes and then runs read += fileChannel.read(...) until read reaches that length. If the file has fewer bytes than File.length() reported, for example because it was truncated in between or because it is a procfs/sysfs file, read(...) returns -1 at end of file. The loop adds -1 and never ends, so the calling thread, often an event loop, spins forever. getChunk(int) already checks for -1. Modifications: - Throw an EOFException when read(...) returns -1 before the array is full. - Add a test with a File whose length() is larger than its content. Result: get(), getByteBuf() and getString() fail with an EOFException instead of spinning forever when the file is shorter than its length.
normanmaurer
approved these changes
|
There was an error while loading. Please reload this page.
🚨 TestLens detected 1 failed test 🚨Test SummaryTip Inspect all details with the TestLens CLI: Build PR / macos-x86_64-java11-boringssl build > Netty/Transport/Native/KQueue
🏷️ Commit: a1e3ac3 Test FailuresKQueueDatagramUnicastIPv6MappedTest > testSimpleSendDirectByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-x86_64-java11-boringssl build)Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Auto-port PR for 5.0: #18002 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could not create auto-port PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…le is short (#18002) Auto-port of #17973 to 5.0 Cherry-picked commit: 66dc5e6 --- Motivation: `AbstractDiskHttpData.readFrom(File)`, which `get()`, `getByteBuf()` and `getString()` use, allocates an array of `File.length()` bytes and then runs `read += fileChannel.read(byteBuffer)` until `read` reaches that length. If the file has fewer bytes than `File.length()` reported, for example because it was truncated in between or because it is a procfs/sysfs file, `read(...)` returns `-1` at end of file. The loop adds `-1` and never ends, so the calling thread, often an event loop, spins forever. `getChunk(int)` already checks for `-1`. Modification: - Throw an `EOFException` when `read(...)` returns `-1` before the array is full. - Add `AbstractDiskHttpDataTest.testGetWhenFileIsShorterThanItsLength`, which uses a `File` whose `length()` is larger than its content. Result: `get()`, `getByteBuf()` and `getString()` fail with an `EOFException` instead of spinning forever when the file is shorter than its length. Co-authored-by: Martin Mirchev <[email protected]>
… short (#17973) (#18004) Motivation: `AbstractDiskHttpData.readFrom(File)`, which `get()`, `getByteBuf()` and `getString()` use, allocates an array of `File.length()` bytes and then runs `read += fileChannel.read(byteBuffer)` until `read` reaches that length. If the file has fewer bytes than `File.length()` reported, for example because it was truncated in between or because it is a procfs/sysfs file, `read(...)` returns `-1` at end of file. The loop adds `-1` and never ends, so the calling thread, often an event loop, spins forever. `getChunk(int)` already checks for `-1`. Modification: - Throw an `EOFException` when `read(...)` returns `-1` before the array is full. - Add `AbstractDiskHttpDataTest.testGetWhenFileIsShorterThanItsLength`, which uses a `File` whose `length()` is larger than its content. Result: `get()`, `getByteBuf()` and `getString()` fail with an `EOFException` instead of spinning forever when the file is shorter than its length. (cherry picked from commit 66dc5e6) --------- Co-authored-by: Martin Mirchev <[email protected]>
… short (netty#17973) (netty#18004) Motivation: `AbstractDiskHttpData.readFrom(File)`, which `get()`, `getByteBuf()` and `getString()` use, allocates an array of `File.length()` bytes and then runs `read += fileChannel.read(byteBuffer)` until `read` reaches that length. If the file has fewer bytes than `File.length()` reported, for example because it was truncated in between or because it is a procfs/sysfs file, `read(...)` returns `-1` at end of file. The loop adds `-1` and never ends, so the calling thread, often an event loop, spins forever. `getChunk(int)` already checks for `-1`. Modification: - Throw an `EOFException` when `read(...)` returns `-1` before the array is full. - Add `AbstractDiskHttpDataTest.testGetWhenFileIsShorterThanItsLength`, which uses a `File` whose `length()` is larger than its content. Result: `get()`, `getByteBuf()` and `getString()` fail with an `EOFException` instead of spinning forever when the file is shorter than its length. (cherry picked from commit 66dc5e6) --------- Co-authored-by: Martin Mirchev <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.