IIS: fix ReadFileChunk latent overflow (allocate m_dwPageSize, not 1) - #3624
IIS: fix ReadFileChunk latent overflow (allocate m_dwPageSize, not 1)#3624A13501350 wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a latent buffer overflow risk in the IIS module’s CMyHttpModule::ReadFileChunk by allocating an I/O scratch buffer sized to the actual read length (m_dwPageSize) rather than relying on VirtualAlloc’s page-rounding behavior.
Changes:
- Update
VirtualAlloccall to allocatem_dwPageSizebytes instead of1, matching theReadFile(..., m_dwPageSize, ...)usage. - Keep existing cleanup behavior (
VirtualFree(..., MEM_RELEASE)) unchanged.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This PR looks good to me - I'll approve and merge it soon. |



Summary
Fixes a latent buffer overflow in
ReadFileChunk(IIS module).The I/O scratch buffer was allocated with
VirtualAlloc(NULL, 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE), yetReadFilewritesm_dwPageSizebytes into it (iis/mymodule.cpp:304,:339). It only worked by accident:VirtualAllocrounds the allocation size up to a full page, and the returned address is page-aligned — so requesting 1 byte commits exactly one page, which happens to equalm_dwPageSize. Ifm_dwPageSizeever differed from the system page size,ReadFilewould write past the committed region (access violation).Fixes
Closes #3623
Changed location
iis/mymodule.cpp:305— allocate the real size:VirtualAlloc(NULL, m_dwPageSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE)The page-aligned address still satisfies the file I/O alignment requirements already used in the function, and the committed size now matches the
ReadFilelength.VirtualFree(pIoBuffer, 0, MEM_RELEASE)cleanup is unchanged.