Repository navigation
Fix constituent table alignment, verify header CRC, add a TCD writer (1.1.0) - #1
Merged
Merged
Conversation
libtcd writes the speed, equilibrium and node-factor tables each into a whole number of bytes. The reader read them as one bit stream, so when the constituent count is not a multiple of 8 (for example 178) every equilibrium argument and node factor came back wrong. Skip the padding bits before each table. Adds a small libtcd-written fixture with 11 constituents, and its generator.
libtcd stores a CRC-32 of the padded ASCII header after it and refuses a file whose header does not match. The reader skipped those 4 bytes and opened a corrupted file without complaint. It now computes the CRC-32 and raises TCD::ChecksumError on a mismatch. Reader.new takes verify_checksum: false to skip the check explicitly.
Writes a TCD file in the layout libtcd 2.2.7 writes: the ASCII header padded to its size, its CRC-32 (big-endian), the string tables, the speed, equilibrium and node-factor tables (each byte-aligned), and the reference and subordinate station records. Bit widths, scales and offsets come from the caller, from the data range as libtcd computes them, or from libtcd's defaults. A value that does not fit its field, or a string over libtcd's length limits or outside ISO-8859-1, raises ArgumentError instead of being truncated. Writer.from_reader copies a file read by the gem; it reproduces the stock XTide file and libtcd's own test fixture byte for byte. A stored level multiply of 0 (which the reader returns as 1.0) is read back from the source so the copy keeps it.
The writer now raises ArgumentError instead of writing a file that libtcd or XTide reads wrong or aborts on, or that the gem cannot read back: - NUL in any string; "__END__" as a table entry - tables over libtcd's index limits (256 for level units, direction units, restrictions and legalese; 32,768 for time zones, countries and datums), and a direction units table without "degrees true" after its first entry - control characters, brackets or edge spaces in header text - fractional values in integer fields, non-finite floats - bit widths over 31, zero scales, negative offsets and equilibrium arguments, out-of-range header integers; a speed range too wide for scale 10^7 now uses the largest power of ten that fits - subordinates whose reference is not a reference record - zone offsets that are not HHMM, invalid dates, epochs outside 0..360, level multipliers that round to 0 - one-entry unit tables get a 1-bit field instead of 0 Errors from bit packing, a missing reference_station, an unknown record_type and zero years are now ArgumentErrors that name the field. A libtcd-backed test runs when TCD_LIBTCD_DUMP points at a binary built from test/fixtures/tcd_fulldump.c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Release 1.1.0. Two new features and one reader fix, all checked against libtcd 2.2.7 and XTide 2.15.6.
What changed
test/fixtures/unaligned-11.tcd(built with libtcd) covers it.Reader.newnow checks the header CRC-32, as libtcd does, and raisesTCD::ChecksumErroron a mismatch.verify_checksum: falseskips it.TCD::Writer(feature). Writes TCD files that libtcd and XTide read, from a reader (Writer.from_reader) or from plain data.ArgumentErrorinstead of writing a corrupt file.Proof
TCD_LIBTCD_DUMP).gem buildbuildstcd-1.1.0.gemwith every lib file included.