record_get() set a TypeError with PyErr_Format() when given the wrong
number of positional arguments but did not return, falling through to
record_item_by_name() with an uninitialized `key` pointer. Depending on
the stack contents this either crashed the interpreter (SEGV) or silently
returned the default instead of raising TypeError. The release build also
emitted a `'key' may be used uninitialized` warning.
Return NULL immediately after setting the error, and add regression
coverage for the invalid argument-count cases.
Fixes MagicStack#1328.
Summary
asyncpg.Record.get() could crash the interpreter (SEGV) — or, depending on stack contents, silently return the default instead of raising TypeError — when called with an invalid number of positional arguments, e.g. r.get() or r.get("a", 2, 3).
In record_get() (asyncpg/protocol/record/recordobj.c), the wrong-argument-count else branch sets a TypeError via PyErr_Format() but does not return. Execution falls through to:
with key left uninitialized, which is undefined behavior — a native crash on release builds. The release build also emitted warning: 'key' may be used uninitialized [-Wmaybe-uninitialized].
Fix
Return NULL immediately after setting the argument-count error:
Tests / Verification
Fixes #1328.
Disclosure: prepared with AI assistance; reviewed and verified locally.