You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A MappedUDT isn't prevented from mirroring a NUL-terminated (typlen -2) type #370
The ability for a MappedUDT to mirror scalar types, not only composite types, appeared fifteen years ago in c525927, along with the apparently definitive comment,
A scalar mapping that is implemented in Java will have ... parse ... and ... toString .... A pure mapping (i.e. no Java I/O methods) will not ....
Indeed, whenever a UDT was first encountered in function resolution, it would be registered with isJavaBasedScalartrue, whereas one first encountered in type resolution, because it appears in the type map, would be registered with isJavaBasedScalarfalse, and would have its parse and toString slots unconditionally nulled.
However, that comment and logic can't be squared with even older logic going back to e0222e3 where _UDT_coerceDatum and _UDT_coerceObject will use the parse and toString slots, not the readSQL and writeSQL slots, if the type has PostgreSQL's NUL-terminated internal form (indicated by typlen of -2).
The builtin PostgreSQL type cstring is such a type. By mapping a PL/Java type to cstring and attempting to use it:
SELECTsqlj.add_type_mapping(
'pg_catalog.cstring',
'org.postgresql.pljava.example.annotation.Point');
SELECT*FROM
(SELECT'blah'::cstring) AS p,
javatest.roundtrip(p) AS (typepg text);
... all these years later, one can get a java.lang.NullPointerException: Cannot read field "acc" because "target" is null in PL/Java 1.6.2, or a backend segfault in 1.5.8.
The failure has nothing to do with blah\0 being invalid as a Point representation. It never gets that far. :)
Activity
Document and enforce MappedUDT/typlen-2 exclusion
jcflack commentedon Oct 10, 2021
Believed resolved in 1.6.3. Should probably be backported to 1.5.
Enforce MappedUDT/typlen-2 exclusion