#1134637 python3-can: will accept PGN 0x0000 and allow the creation of undereadble .blf files

#1134637#5
Date:
2026-04-22 13:34:45 UTC
From:
To:
Hi,

While debugging a more complex problem; I came up with this simple reproducer.
This does not completely fix my issues but uncover an undesired pitfall.


Here is a reproducer that creates a good.blf and a bad.blf

Reading the bad.blf will chockes on "BLFParseError("Could not find next object")".

I think that python-can should forbid the creation of unereadable files.

Explicitely setting is_extended_id=True does not helper either.

Greetings

Alexandre
-----

#!/usr/bin/python3

import can

DATA = b'\xff' * 8
ZERO = b'\x00' * 8

def good() -> None:
    writer = can.BLFWriter('good.blf')
    timestamp = 0.0
    for _ in range(10):
        for pgn in range(0xf001,0xf00e):
            print('.', end='')
            timestamp += 0.1
            arbitration_id = pgn << 8
            msg = can.Message(timestamp=timestamp, arbitration_id=arbitration_id, data=DATA)
            writer.on_message_received(msg)
    writer.on_message_received(msg)
    writer.stop()

good()

print('', flush=True)

def bad() -> None:
    writer = can.BLFWriter('bad.blf')
    timestamp = 0.0
    for _ in range(10):
        for pgn in range(0xf001,0xf00e):
            timestamp += 0.1
            arbitration_id = pgn << 8
            msg = can.Message(timestamp=timestamp, arbitration_id=arbitration_id, data=DATA)
            writer.on_message_received(msg)

    # add ZERO's
    for _ in range(10):
        timestamp += 0.1
        pgn = 0
        arbitration_id = pgn << 8
        msg = can.Message(timestamp=timestamp, arbitration_id=arbitration_id, data=ZERO)
        writer.on_message_received(msg)

    for _ in range(10):
        for pgn in range(0xf001,0xf00e):
            timestamp += 0.1
            arbitration_id = pgn << 8
            msg = can.Message(timestamp=timestamp, arbitration_id=arbitration_id, data=DATA)
            writer.on_message_received(msg)

    writer.stop()

bad()

#1134637#10
Date:
2026-04-23 20:46:53 UTC
From:
To:
Hi,

I tried you snipped and indeed the bad.blf contains a block with PGN 0x0
and payload 0x0.

I am reading both blfs with the code below:
def readBLF(filename) -> None:
    print('reading', filename)
    with can.BLFReader(filename + '.blf') as reader:
        for msg in reader:
            print(msg)

But this code does not raise any Error. python-can is 4.6.1.

Best,

#1134637#15
Date:
2026-05-31 11:40:53 UTC
From:
To:
I'm packaging python-vblf as a workaround;
this other library allows me to skip only one bad record,
not the full remaining of the file.

I can now pinpoint the exact record out of thousands of other records
which makes python-can crash.

I will come back at this later.