Oracle 9i (fv2): fix describe desync on NOT-NULL columns, report null_ok#218
Merged
Conversation
The per-column tail of the fv2 describe (0x62 RPA) is `<OAC> null_ok(1B) namelen_bytes(1B) ub4(namelen_chars) DALC(name) 00 00`. `decode_fv2_describe` read the first two bytes as a ub4 name-length, which only works when the leading byte is 0x01. That byte is actually `null_ok` (0x00 NOT NULL, 0x01 nullable): a nullable column sends 0x01, read as a width-1 ub4 whose value coincidentally equals the name length, so the bug stayed hidden. A NOT-NULL column sends 0x00, which decode_ub4 reads as width-0/value-0 (one byte) — the column stream slips, the name garbles (USERNAME -> b'\x08USERNAM'), and a multi-column NOT-NULL fetch then dies with ORA-03115. Every offline fixture was `SELECT <literal> AS name FROM dual`; a literal is always nullable, so null_ok was always 0x01 and the slip never triggered. Read null_ok + the 1-byte byte-length explicitly, then the genuine ub4 char-length. null_ok now feeds Cursor.description[6], so 9i column nullability is reported instead of being hardcoded nullable. Fix lives in the shared tns.py decoder, so sync and async both get it. Added an offline regression fixture from a live 9.2.0.4 capture of two identical-length names differing only in NOT NULL vs nullable, and updated PROTOCOL.md §19.1. Verified live on 9.2.0.4 (all_users, all_tables, a NOT-NULL/nullable table) and confirmed the 10g+ DCB path is unaffected. Closes #217 refs #97 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
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.
What
Fixes the 9i field-version-2 describe decoder (
decode_fv2_describe), which desynced on any NOT NULL column.The per-column tail after the OAC is:
The decoder read the first two bytes as a
ub4name-length. The leading byte is actuallynull_ok(0x00NOT NULL,0x01nullable):0x01, read as a width-1ub4whose value coincidentally equals the name length → looked correct.0x00, read as width-0/value-0 (one byte) → stream slips, name garbles (USERNAME→b'\x08USERNAM'), and a multi-column NOT-NULL fetch dies with ORA-03115.Every offline fixture was
SELECT <literal> AS name FROM dual— literals are always nullable, sonull_okwas always0x01and the slip never triggered. Real dictionary/table columns are NOT NULL and reproduce it.Changes
oracle/tns.py— readnull_ok+ the 1-byte byte-length explicitly, then the genuineub4char-length. Shared decoder, so sync and async are covered.null_oknow feedsCursor.description[6]; 9i column nullability was previously hardcoded nullable.tests/test_tns_decode.py— regression fixture from a live 9.2.0.4 capture of two identical-length names differing only in NOT NULL vs nullable (the exact blind spot); asserts names +null_ok.docs/PROTOCOL.md §19.1— corrected the layout; documented thenull_oktrap; dropped the "validated against eight live captures" over-claim (all eight were nullable dual-aliases).Testing
all_users.username,all_tables(2-col), and a NOT-NULL/nullable table — names correct, ORA-03115 gone,null_okaccurate.Root-caused via a controlled NOT-NULL-vs-nullable experiment and cross-checked against an independent 9i client implementation.
Closes #217