notroj opened a new pull request, #78: URL: https://github.com/apache/apr/pull/78
Two changes to `apr_mmap_create()` on 1.8.x. ### Track the page offset without over-allocating `apr_mmap_t` Since r1887497 (PR 65158), `apr_mmap_create()` on Unix maps from the start of the page containing the requested offset. Because `apr_mmap_t` is a complete public type, the offset within the page was stored after the end of the struct, in a private `struct mm_layout` wrapper. For an `apr_mmap_t` which APR did not allocate, `apr_mmap_dup()` and `apr_mmap_delete()` then read beyond the end of the struct and pass the result to `munmap()`. That change was reverted from 1.7.x in r1902372 after an objection on dev@ to altering the size of the structure: https://lists.apache.org/thread/jt7by9hhvsnpo5ztjmbq5rrpnq2n0b8v The start of a mapping is always page-aligned, so the offset can be derived from `mm->mm` when the region is unmapped. This removes `struct mm_layout` and its helpers: - `apr_mmap_t` is allocated and copied at its public size again. - The `mmap()` and `munmap()` calls made are unchanged. - No 1.8.x release has shipped with the `mm_layout` form. The same form would be suitable for 1.7.x, since it changes neither the struct nor its allocation. ### Merge r1940313 from trunk Allocate the `apr_mmap_t` only once the file has been mapped, so a failed call does not consume memory from the pool. Partial fix for httpd PR 70167. The source changes are adapted by hand: 1.8.x differs from trunk in the BeOS path and in the Windows struct members. ### Tests - `test_mmap_dup` (new): dup into another pool, delete the original, read through the dup, delete the dup; run at each test offset including the unaligned one. - `test_mmap_create_fail` (from trunk): a failed `apr_mmap_create()` does not allocate from the pool. Only effective in a pool-debug build. On Linux x86_64 the full test suite passes with the first commit, and `testmmap` passes with both, in normal and pool-debug builds. An unmodified APR-util 1.6.x run against this library reads a FILE bucket at an unaligned offset as MMAP buckets. The Windows and BeOS changes are not compiled or tested. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
