pipewire/test
Barnabás Pőcze 0b08468035 pipewire: mem: pw_memblock_map(): fix pointer when reusing mapping
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: 2caf81c97c ("mem: improve memory handling")
Fixes #4884
2025-09-08 11:38:42 +00:00
..
data json: fix high surrogate escapes 2024-05-05 15:15:54 +03:00
meson.build pipewire: mem: pw_memblock_map(): fix pointer when reusing mapping 2025-09-08 11:38:42 +00:00
pwtest-compat.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
pwtest-implementation.h treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
pwtest.c pwtest: is_debugger_attached(): rework test 2025-08-13 07:14:33 +00:00
pwtest.h *: unify config.h handling 2025-05-30 10:24:13 +00:00
test-array.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-client.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-config.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-context.c test: fix test 2023-07-19 11:35:03 +02:00
test-example.c examples: surround loop_iterate() with enter() and leave() 2025-01-20 12:00:02 +01:00
test-functional.c test: fix test library path and fix test-functional with ASAN 2025-08-04 08:34:02 +00:00
test-lib.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-logger.c meson.build: rework systemd related options 2025-07-18 09:46:17 +00:00
test-loop.c keys: add and use some loop keys 2024-04-23 11:49:12 +02:00
test-map.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-mempool.c pipewire: mem: pw_memblock_map(): fix pointer when reusing mapping 2025-09-08 11:38:42 +00:00
test-properties.c Fix typos 2024-05-22 09:19:34 +02:00
test-pwtest.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-spa-buffer.c meta: add explicit sync metadata and data type 2024-04-25 09:55:19 +02:00
test-spa-control.c control: improve UMP to Midi conversiom 2025-08-19 18:33:59 +02:00
test-spa-json.c test: format float values with . 2025-07-07 12:09:55 +02:00
test-spa-log.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-spa-node.c spa: revert peer_enum_params node event again 2024-06-20 10:22:45 +02:00
test-spa-pod.c mixer: rework the control mixers to use the parser 2025-07-29 15:33:43 +02:00
test-spa-utils.c test: spa-utils: utils_snprintf_abort_neg_size: remove valgrind check 2025-08-13 07:14:33 +00:00
test-support.c treewide: use SPDX tags to specify copyright information 2023-02-16 10:54:48 +00:00
test-utils.c test: add two minimal tests for pw_strv_parse() 2024-04-27 15:21:05 +02:00