Skip to content

Fix region prioritization in dump_process_memory. - #235

Open
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-dump-process-memory-priority
Open

Fix region prioritization in dump_process_memory.#235
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-dump-process-memory-priority

Conversation

@grrrrrrrrr

Copy link
Copy Markdown
Collaborator

dump_process_memory::sort_by_priority contained two algorithmic flaws:

  1. When iterating over sorted offsets, regions preceding the current
    offset were popped and placed at the back with deque.push_back.
    Because these regions were consumed from the iterator, subsequent
    offset iterations could no longer match them, dropping regions from
    consideration and scrambling the non-priority region order.
  2. Matched priority regions were prepended using deque.push_front,
    which reversed the requested relative priority order when multiple
    priority offsets matched distinct regions.

This change refactors the function to partition the memory regions into
priority and non-priority collections by checking whether any address in
offsets falls within [start_address, end_address) using binary search,
preserving the original monotonic address order for both groups.

`dump_process_memory::sort_by_priority` contained two algorithmic flaws:

1. When iterating over sorted `offsets`, regions preceding the current
   offset were popped and placed at the back with `deque.push_back`.
   Because these regions were consumed from the iterator, subsequent
   offset iterations could no longer match them, dropping regions from
   consideration and scrambling the non-priority region order.
2. Matched priority regions were prepended using `deque.push_front`,
   which reversed the requested relative priority order when multiple
   priority offsets matched distinct regions.

This change refactors the function to partition the memory regions into
priority and non-priority collections by checking whether any address in
`offsets` falls within `[start_address, end_address)` using binary search,
preserving the original monotonic address order for both groups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant