Prototype safer AisBitset access wrapper #175
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to improve memory safety in message parsing, by checking whether callers to AisBitset::ToUnsignedInt() etc are reading too far, and returning an error that's easily attached to the Ais object for callers to see. If asserts are enabled, however, it dies on one in the usual way.
This suggestion is particularly prompted by the recent issues raised by fuzzing, so I've converted Ais20 and Ais26 to use the new system, addressing #174 and #171. If asserts are enabled it continues to die essentially as documented in the issue, or if not then the relevant Ais objects are successfully constructed with status set to AIS_ERR_BAD_BIT_COUNT.
I haven't tested to see whether this affects performance yet - I'm happy to have a look if there's a standard project method based on public data. If there's significant degradation then I think it's possible to do something very similar statically, using the same number of branches as currently exist. That would be an ugly mess of templates, however.