Skip to content

Commit 92ff4b6

Browse files
committed
fix: validate jitdump filename PID matches MMAP2 record PID
Match perf's jit_detect() behavior: the PID embedded in the jitdump filename must match the MMAP2 record's PID. Also fixes a bug where rposition returned a usize that was incorrectly used as a byte slice.
1 parent fc2b18e commit 92ff4b6

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

src/executor/wall_time/perf/parse_perf_file.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn parse_for_memmap2<P: AsRef<Path>>(
111111
// Collect jitdump file paths before the PROT_EXEC filter in process_mmap2_record
112112
// skips them. JIT runtimes mmap the jitdump file so perf records it.
113113
// Match perf's jit_detect(): basename must be `jit-<pid>.dump`.
114-
if is_jit_dump_path(&mmap2_record.path.as_slice()) {
114+
if is_jit_dump_path(&mmap2_record.path.as_slice(), mmap2_record.pid) {
115115
let path = PathBuf::from(
116116
String::from_utf8_lossy(&mmap2_record.path.as_slice()).into_owned(),
117117
);
@@ -180,21 +180,15 @@ impl PidFilter {
180180
}
181181
}
182182

183-
/// Returns true if the path basename matches perf's jitdump pattern: `jit-<digits>.dump`.
184-
fn is_jit_dump_path(path: &[u8]) -> bool {
185-
let basename = match path.iter().rposition(|&b| b == b'/') {
186-
Some(pos) => &path[pos + 1..],
187-
None => return false,
183+
/// Returns true if the path basename matches perf's `jit_detect()` pattern: `jit-<pid>.dump`,
184+
/// where `<pid>` must match the MMAP2 record's PID.
185+
fn is_jit_dump_path(path: &[u8], pid: pid_t) -> bool {
186+
let Some(pos) = path.iter().rposition(|&b| b == b'/') else {
187+
return false;
188188
};
189-
let rest = match basename.strip_prefix(b"jit-") {
190-
Some(rest) => rest,
191-
None => return false,
192-
};
193-
let rest = match rest.strip_suffix(b".dump") {
194-
Some(rest) => rest,
195-
None => return false,
196-
};
197-
!rest.is_empty() && rest.iter().all(|b| b.is_ascii_digit())
189+
let basename = &path[pos + 1..];
190+
let expected = format!("jit-{pid}.dump");
191+
basename == expected.as_bytes()
198192
}
199193

200194
/// Process a single MMAP2 record and add it to the symbols and unwind data maps

0 commit comments

Comments
 (0)