Repository navigation
Conversation
apr_mmap_create() maps from the start of the page containing the requested offset, since r1887497 (with follow-up r1887508), which this branch inherited from 1.7.x. That change stored the offset of the data within the page after the end of the apr_mmap_t, in a private structure wrapping it. For an apr_mmap_t which was not allocated by APR, apr_mmap_dup() and apr_mmap_delete() would then read beyond the end of the structure and pass the result to munmap(). r1887497 and r1887508 were 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 instead be derived from the ->mm pointer when the region is unmapped, with no change to the size or allocation of apr_mmap_t. The mmap() and munmap() calls made are unchanged. * mmap/unix/mmap.c (struct mm_layout, alloc_with_poffset, set_poffset, get_poffset): Remove. (page_offset): New function. (mmap_cleanup): Use it to derive the start of the mapping. (apr_mmap_create): Use it, and allocate only an apr_mmap_t. (apr_mmap_dup): Copy only an apr_mmap_t. * test/testmmap.c (test_mmap_dup): New test. (testmmap): Run it. PR: 65158 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Avoid allocating from the pool when apr_mmap_create() fails. A caller which repeatedly fails to map a file, such as a FILE bucket being read in chunks, otherwise consumes memory from the pool for each attempt, for the lifetime of that pool. This is a partial fix for httpd PR 70167: it removes the memory growth per failed call, but does not stop the FILE bucket retrying a failed mmap for each read. * mmap/unix/mmap.c, mmap/win32/mmap.c (apr_mmap_create): Allocate the apr_mmap_t only once the file has been mapped. * test/testmmap.c (test_mmap_create_fail): New test. (testmmap): Run it. PR: 70167 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes to
apr_mmap_create()on 1.8.x.Track the page offset without over-allocating
apr_mmap_tSince r1887497 (PR 65158),
apr_mmap_create()on Unix maps from the start of the page containing the requested offset. Becauseapr_mmap_tis a complete public type, the offset within the page was stored after the end of the struct, in a privatestruct mm_layoutwrapper.For an
apr_mmap_twhich APR did not allocate,apr_mmap_dup()andapr_mmap_delete()then read beyond the end of the struct and pass the result tomunmap(). 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/jt7by9hhvsnpo5ztjmbq5rrpnq2n0b8vThe start of a mapping is always page-aligned, so the offset can be derived from
mm->mmwhen the region is unmapped. This removesstruct mm_layoutand its helpers:apr_mmap_tis allocated and copied at its public size again.mmap()andmunmap()calls made are unchanged.mm_layoutform.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_tonly 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 failedapr_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
testmmappasses 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