Fix ToBytes corrupting entries lacking the 32-bit kvno extension (#2)#4
Merged
Conversation
ToBytes always appended a 32-bit key version number to every entry, even those parsed without the optional 32-bit kvno extension. This added 4 bytes per entry and inflated each entry's size field, so loading a standard keytab and writing it back produced a larger, corrupt file (example.kt: 204 -> 216 bytes). Track whether the extension was present when parsing (HasVno) and emit the 32-bit vno from ToBytes only when it is, so entries without the extension round-trip to identical bytes. Fixes #2
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.
Linked Issue
Closes #2Root Cause
The 32-bit key version number is an optional trailing extension to a keytab entry, present only when at least 4 bytes remain in the record.
FromBytesread it conditionally but did not record whether it had been present, soToByteshad no way to tell entries that carried the extension from those that did not — and it appended the 32-bit vno unconditionally. Every serialized entry therefore gained 4 trailing bytes and an inflated size field, corrupting any keytab that was loaded and written back.Fix Description
Add a
HasVnofield toKeytabEntrythatFromBytessets when the 32-bit kvno extension is present.ToBytesnow emits the 32-bit vno only whenHasVnois true. Entries parsed without the extension serialize back to byte-identical output; entries parsed with it preserve it. Newly constructed entries default toHasVno = false, matching modern keytabs that omit the extension.How Verified
go test ./...passes, including new tests.example.ktand re-serializing now produces an identical 204-byte buffer; entry size fields stay0x0000003a, where before the round-trip produced 216 bytes with size0x0000003e.Test Coverage
src/keytab/KeytabEntry_kvno_test.go:Test_KeytabEntry_NoKvnoRoundTrip— an entry without the extension serializes to identical bytes andHasVnois false.Test_KeytabEntry_KvnoRoundTrip— an entry with the extension preserves the 32-bit vno andHasVnois true.Scope of Change
src/keytab/KeytabEntry.go,src/keytab/KeytabEntry_kvno_test.goRisk and Rollout
Output-only change to entry serialization; existing involution tests still pass. Safe to merge directly.