[MDEV-30200] Inconsistent UDF behavior with respect to `max_length` Created: 2022-12-12 Updated: 2023-11-28 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.9, 10.10 |
| Fix Version/s: | 10.4, 10.5, 10.6, 10.11 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Trevor Gross | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | UDF | ||
| Environment: |
`mariadb:10.9` and `mariadb:10.10` docker images |
||
| Description |
|
There is some inconsistent behavior for the `result`/`length` behavior in string-based user-defined functions. This isn't exactly documented in MariaDB, but from the MySQL docs:
MariaDB and MySQL have the same behavior: if a `cfg.max_length` is set in `xxx_init()` that is less than 255, then the `result` buffer will have a length of 766 when `xxx()` is called (I am unsure why 766 and not `cfg.max_length`). However, this behavior differs when `xxx` is called within another function or in some different contexts, e.g. `yyy(xxx())`. For some reason, this pattern makes MariaDB pass a `length` of 0 to `xxx()`, rather than the expected `max_length` or 755.
Example of the problem: logs when running `set @testval = (select lookup6('0.0.0.0'))`
Source that catches this error: https://github.com/pluots/sql-udf/tree/4e4ded2f1f24bdb1052fe45262f73e87d5f1e2bb |
| Comments |
| Comment by Trevor Gross [ 2022-12-12 ] | |||||||||||||||||||
|
Minimum reproduction: code:
Output:
| |||||||||||||||||||
| Comment by Trevor Gross [ 2022-12-12 ] | |||||||||||||||||||
|
In testing, if I disregard the initial length and write to the buffer anyway, I still get the correct result. This makes me think the buffer still exists at the proper size (755) but the length just isn't getting passed correctly to the call. Neither of the `char*` examples (metaphon, is_const) check the `*length` value but they probably should since they're technically overwriting their allowed buffers | |||||||||||||||||||
| Comment by Trevor Gross [ 2022-12-12 ] | |||||||||||||||||||
|
xref mysql issue: https://bugs.mysql.com/bug.php?id=109335 |