YWHKKX opened a new pull request, #19704: URL: https://github.com/apache/nuttx/pull/19704
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary `fs_pseudofile.c` grows the in-memory file buffer with a power-of-two size derived from `LOG2_CEIL`. For some large requested sizes that rounding is not representable as a `size_t` shift, so expand can allocate a buffer smaller than the logical end position used by a later `memcpy`. This change: - Adds a small helper to choose an allocation size that always covers the requested length (exact size when power-of-two rounding is not safe) - Rejects write lengths that wrap `size_t` before calling expand - Clears newly addressed bytes when the file grows - Routes truncate growth through the same expand path ## Impact - Users: behavior of pseudo regular files (`CONFIG_PSEUDOFS_FILE`) when extending past the current size - Build: no build-system or Kconfig changes - Hardware / docs: none - Compatibility: API unchanged; large expands that previously under-sized the buffer now allocate correctly or fail with `-ENOMEM` / `-EFBIG` as appropriate ## Testing - Host: Windows 10, reviewed `fs/vfs/fs_pseudofile.c` expand/write/truncate paths after rebasing onto current `master` - Checked allocation-size selection for a large expand request (`f_pos` near `INT_MAX` plus a small write length): previous `1 << LOG2_CEIL(size)` path under-sized the buffer; the new helper returns a size that covers the request - Confirmed the expand path no longer passes an unchecked `1 << LOG2_CEIL(size)` directly to `fs_heap_realloc` - Full `sim` rebuild was not run in this environment; please exercise an existing `CONFIG_PSEUDOFS_FILE=y` configuration if additional runtime coverage is desired **PR verification Self-Check** * [x] This PR introduces only one functional change. * [x] I have updated all required description fields above. * [x] My PR adheres to Contributing Guidelines (git commit --trailer "Co-authored-by: Cursor <[email protected]>" title and message, coding standard, etc). * [ ] My PR is still work in progress (not ready for review). * [x] My PR is ready for review and can be safely merged into a codebase. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
