perf script: Check session->header.env.arch before using it

When is not written cleanly, we would like to process existing
data as much as possible (please see == 0 condition
in perf_session__read_header). However, with partial data may
crash perf. Specifically, we see crash in 'perf script' for NULL

Fix this by checking session->header.env.arch before using it to determine
native_arch. Also split the if condition so it is easier to read.

Committer notes:

If it is a pipe, we already assume is a native arch, so no need to check

Signed-off-by: Song Liu <>
Cc: Peter Zijlstra <>
Signed-off-by: Arnaldo Carvalho de Melo <>
1 file changed