Fixed: Remove UB-prone uninit slice cast in blocking webfetch#41
Conversation
Use an initialized [0u8; 8192] stack buffer in the blocking read loop instead of casting MaybeUninit memory to [u8]. This removes UB risk while preserving chunked reads and size checks.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
🧰 Additional context used📓 Path-based instructions (1)src/**/*.rs📄 CodeRabbit inference engine (src/AGENTS.md)
Files:
🧠 Learnings (3)📓 Common learnings📚 Learning: 2026-02-07T22:53:26.067ZApplied to files:
📚 Learning: 2026-02-07T22:53:26.067ZApplied to files:
🧬 Code graph analysis (1)src/llm-coding-tools-core/src/tools/webfetch/blocking_impl.rs (1)
🔇 Additional comments (2)
WalkthroughThis change modifies the web fetch blocking implementation by replacing an unsafe MaybeUninit-based buffer with a direct [u8; 8192] stack-allocated byte array. The unsafe pointer arithmetic and raw pointer slice construction are removed in favor of directly calling read(&mut buffer). Data extraction adjusts to use &buffer[..n] instead. The refactoring preserves byte accumulation logic, content length validation, streaming until EOF, and error handling via ToolError::Http. No public API signatures are affected. The change results in a net reduction of 7 lines of code. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
==========================================
- Coverage 74.91% 74.84% -0.07%
==========================================
Files 67 67
Lines 1985 1980 -5
==========================================
- Hits 1487 1482 -5
Misses 498 498
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Fixed: Remove UB-prone uninit slice cast in blocking webfetch
Summary
MaybeUninitslice casting in the blocking webfetch read loop with a safe initialized[0u8; 8192]buffer.&mut [u8]over uninitialized memory.Basically, the old behaviour was technically correct.
But the slice constructor assumes that the data is 'initialized'.
I don't want to risk it with future compiler changes.