[PATCH 0/3] tools/mm: page_owner_sort: three input-handling fixes
From: Henrique Godoy
Date: Wed Nov 04 2026 - 14:23:53 EST
These three patches are fixes for tools/mm/page_owner_sort.c and are
independent of the out-of-bounds series posted a moment ago; they touch the
record reader and the array of records.
1/3 keeps a record that ends the file. A dump whose last record is not
followed by an empty line loses that record: ten records load as nine,
and the tenth disappears without a word.
2/3 stops reading a full buffer as the end of the file. read_block()
returns -1 both at the end of the file and when a record does not fit
in BUF_SIZE, so a dump carrying a long record is sorted as if the file
ended there:
$ ./page_owner_sort dump.txt out.txt
loaded 0
With the patch it reports the record that does not fit, with the name
of the file, and exits with a non-zero status.
3/3 grows the array of records instead of deriving its size from
st.st_size / 100. A dump whose records are shorter than 100 bytes
holds more records than that, so a valid input is rejected:
$ ./page_owner_sort dump.txt out.txt
max_size too small??
Measured on a dump of 200 records of 93 bytes: before, no output at
all; after, all 200 records sorted.
The three inputs above are the reproduction cases: 9 records loaded before
and 10 after, "loaded 0" before and an error naming the file after, and
"max_size too small??" before and 200 records after.
The output of the tool on a realistic dump is byte for byte the same before
and after the series, and checkpatch --strict reports 0 errors, 0 warnings
and 0 checks on each patch.