mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
Previously the pointer was determined as follows:
mm->this.ptr = SPA_PTROFF(m->ptr, range.start, void);
however, when `pw_map_range` is calculated, `pw_map_range::start` is the offset
from the beginning of the first page, starting at `pw_map_range::offset`.
This works correctly if `memblock_map()` runs because that will map the file
with expected offset, so using `range.start` is correct.
However, when a mapping is reused (i.e. `memblock_find_mapping()`) finds something,
then `range.start` is not necessarily correct. Consider the following example:
* page size is 10
* one memblock with size 20 (2 pages)
* the applications wants to mappings:
* (offset=5,size=10)
* (offset=15,size=5)
After the first request from the application, a `mapping` object is created
that covers the first two pages of the memblock: offset=0 and size=20. During
the second request, the calculated `pw_map_range` is as follows:
{ start = 5, offset = 10, size = 10 }
and the only previously created mapping is reused since (0 <= 5) and (10 <= 20). When
the pointer of the mapping is adjusted afterwards it will be incorrect since `m->ptr`
points to byte 0 on page 0 (instead of byte 0 on page 1 -- that is assumed). Thereforce
the two will unexpectedly overlap.
Fix that by using `offset - m->offset` when adjusting the mapping's pointer. Also move
the `range` variable into a smaller scope because it only makes sense there. And add
a test that check the above previously incorrect case.
Fixes:
|
||
|---|---|---|
| .. | ||
| data | ||
| meson.build | ||
| pwtest-compat.c | ||
| pwtest-implementation.h | ||
| pwtest.c | ||
| pwtest.h | ||
| test-array.c | ||
| test-client.c | ||
| test-config.c | ||
| test-context.c | ||
| test-example.c | ||
| test-functional.c | ||
| test-lib.c | ||
| test-logger.c | ||
| test-loop.c | ||
| test-map.c | ||
| test-mempool.c | ||
| test-properties.c | ||
| test-pwtest.c | ||
| test-spa-buffer.c | ||
| test-spa-control.c | ||
| test-spa-json.c | ||
| test-spa-log.c | ||
| test-spa-node.c | ||
| test-spa-pod.c | ||
| test-spa-utils.c | ||
| test-support.c | ||
| test-utils.c | ||