File "/.../lib/python3.15/profiling/sampling/heatmap_collector.py", line 905, in _generate_file_html
source_lines = Path(filename).read_text(encoding='utf-8', errors='replace').splitlines()
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../lib/python3.15/pathlib/__init__.py", line 985, in read_text
with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f:
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../lib/python3.15/pathlib/__init__.py", line 969, in open
return io.open(self, mode, buffering, encoding, errors, newline)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: embedded null byte
Let me try to figure out a repro or shareable dump.
In the meantime, here's something maybe useful from the bad file I have:
>>> collector = CollapsedStackCollector(interval)
>>> count = reader.replay_samples(collector, None)
>>> next(k for k in collector.stack_counter if r"\x00" in repr(k))
((<many tuples of (filename, lineno, func)>, ('\x00', 0, '`@')), 17992827)
There is a second instance as well. That one is:
>>> [k for k in collector.stack_counter if r"\x00" in repr(k)][1]
((<many tuples of (filename, lineno, func)>, ('\x00', 0, 'P'), (filename, lineno, func)), 17992827)
Activity
StanFromIreland commented on Jan 30, 2026
Maybe after reading the filename in parse_code_object, we should check the content and not just the length? WDYT @pablogsal
pablogsal commented on Jan 30, 2026
Unfortunately not :(
If you could have a repro or you can send over the file that would be amazing!
pablogsal commented on Jan 30, 2026
Oh wait this is opening a python file:
File "/.../lib/python3.15/profiling/sampling/heatmap_collector.py", line 905, in _generate_file_html source_lines = Path(filename).read_text(encoding='utf-8', errors='replace').splitlines() ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.15/pathlib/__init__.py", line 985, in read_text with self.open(mode='r', encoding=encoding, errors=errors, newline=newline) as f: ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/.../lib/python3.15/pathlib/__init__.py", line 969, in open return io.open(self, mode, buffering, encoding, errors, newline) ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: embedded null byteIt's here:
cpython/Lib/profiling/sampling/heatmap_collector.py
Line 905 in 96e4cd6
Is not the result file is just a python file!
pablogsal commented on Jan 30, 2026
Ah damn, ok, the filename comes from stat.filename. Yeah I think i still would like to see at least the file
hauntsaninja commented on Feb 2, 2026
Let me try to figure out a repro or shareable dump.
In the meantime, here's something maybe useful from the bad file I have:
>>> collector = CollapsedStackCollector(interval) >>> count = reader.replay_samples(collector, None) >>> next(k for k in collector.stack_counter if r"\x00" in repr(k)) ((<many tuples of (filename, lineno, func)>, ('\x00', 0, '`@')), 17992827)There is a second instance as well. That one is:
>>> [k for k in collector.stack_counter if r"\x00" in repr(k)][1] ((<many tuples of (filename, lineno, func)>, ('\x00', 0, 'P'), (filename, lineno, func)), 17992827)pablogsal commented on Feb 3, 2026
@hauntsaninja can you try to apply this diff and see if it reproduces?
ivonastojanovic commented on Oct 23, 2026
Closing this one since this was fixed in #158853.