schwehr / libais

C++ decoder for Automatic Identification System for tracking ships and decoding maritime information
Other
215 stars 94 forks source link

spare bits in Ais6_1_5 #163

Closed cchayden closed 6 years ago

cchayden commented 6 years ago

The bitset ToUnsignedInt can handle up to 32 bits at a time: its second argument cannot be larger than 32. In processing ais6.cpp, in Ais6_1_5 ToUnsignedInt is called with a length argument greater than 32, causing a core dump.

This change breaks the reading of the spare bits into two chunks, so as not to exceed 32 bits.

jamtho commented 6 years ago

The alternative being to preserve the ABI and discard the last 17 bits, since they're officially unused, documenting the behaviour.

I prefer your solution as it seems obviously the Right Thing, and I always link libais statically in deployments, so it wouldn't cause a problem in practice to me at least. Not sure about other people though.

himikof commented 6 years ago

This seems mostly the same as #148.

schwehr commented 6 years ago

@cchayden , Thanks! This PR is an improvement over #148 by initializing spare2. Can you please merge in 65cb1b12d65ebab97a34f4e54daaae81eab4b949 and then I'll merge this pull request. After that, I'll merge in the test I just added.

@himikof Thanks for reminding me of #148