+ tools-mm-thpmaps-handle-carriage-returns-and-non-utf-8-filenames.patch added to mm-nonmm-unstable branch
Andrew Morton
tree noticeThe patch titled
Subject: tools/mm/thpmaps: handle carriage returns and non-UTF-8 filenames
has been added to the -mm mm-nonmm-unstable branch. Its filename is
tools-mm-thpmaps-handle-carriage-returns-and-non-utf-8-filenames.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/tools-mm-thpmaps-handle-carriage-returns-and-non-utf-8-filenames.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Weilin Tong <[email protected]>
Subject: tools/mm/thpmaps: handle carriage returns and non-UTF-8 filenames
Date: Wed, 04 Nov 2026 14:16:41 +0800
VMAList opens smaps with universal newline handling and strict decoding. A carriage return in a mapped filename can split a header into multiple records, while non-UTF-8 bytes cause UnicodeDecodeError.
Read LF-terminated records and use surrogateescape to preserve filename bytes. Escape filename characters that stdout cannot encode to avoid UnicodeEncodeError when printing mapping names.
---
tools/mm/thpmaps | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
tools/mm/thpmaps renamed from tools/mm/thpmaps~tools-mm-thpmaps-handle-carriage-returns-and-non-utf-8-filenames +5 -2
@@ -196,7 +196,8 @@ class VMAList: # instance to receive VMAs. def __init__(self, pid='self', stats=[]): self.vmas = [] - with open(f'/proc/{pid}/smaps', 'r') as file: + with open(f'/proc/{pid}/smaps', 'r', newline='\n', + errors='surrogateescape') as file: for line in file: elements = line.rstrip('\n').split(maxsplit=5) if '-' in elements[0]:
@@ -363,12 +364,14 @@ def cont_parse(vma, order, ranges, anons def vma_print(vma, pid): # Prints a VMA instance in a format similar to smaps. The main difference is # that the pid is included as the first value. + name = vma.name.encode(sys.stdout.encoding, errors='backslashreplace') + name = name.decode(sys.stdout.encoding) print("{:010d}: {:016x}-{:016x} {}{}{}{} {:08x} {:02x}:{:02x} {:08x} {}" .format( pid, vma.start, vma.end, 'r' if vma.read else '-', 'w' if vma.write else '-', 'x' if vma.execute else '-', 'p' if vma.private else 's', - vma.pgoff, vma.major, vma.minor, vma.inode, vma.name + vma.pgoff, vma.major, vma.minor, vma.inode, name ))
_
Patches currently in -mm which might be from [email protected] are
tools-mm-thpmaps-fix-partial-thp-anon-file-accounting.patch tools-mm-thpmaps-fix-missing-order-1-file-thp-statistics.patch tools-mm-thpmaps-fix-missing-mapping-names.patch tools-mm-thpmaps-handle-carriage-returns-and-non-utf-8-filenames.patch