Skip to content

Bug in index.ts when parsing message 24 #16

Description

@neillj

Hi Doron

I think I've found a bug in the src/lib/index.ts when receiving a message 24A. You have

case 24:
    report = parseStaticDataReport(
    this.bitarray, aisType, repeat,
    (session.sequence_id === 1 ? MESSAGE_PART.A : MESSAGE_PART.B),
    mmsi)
    break

but the session object for a 24A with a message of e.g. "!AIVDO,1,1,,B,H3P<........,2*46" won't necessarily have a session object defined at this point as the code relies on messageCounter>1 to define it and here that is 1. This results in it decoding part B by mistake in this case as the identity to 1 fails for an empty object. The message I've quoted is from messages recorded live so, even it isn't following the standard does exist 'in the wild'.

The fix that works for me is

case 24:
    report = parseStaticDataReport(
    this.bitarray, aisType, repeat,
    ((Object.keys(session).length === 0 || session.sequence_id === 1) ? MESSAGE_PART.A : MESSAGE_PART.B),
    mmsi)
    break

where there's a check to make sure the session has been defined (multipart message) or hasn't been (single message).

Thanks for the plugin !

Neill

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions