Skip to content

Conversation

@jrgemignani
Copy link
Contributor

@jrgemignani jrgemignani commented Jul 30, 2024

Fixed the issue with creating a label name close to MAX_LABEL_NAME_LEN. Well, sort of.

The issue here is that a label name is the name of a relation in PostgreSQL. While the relation name is a char * it is basically converted to a PG type Name when it is used to create a relation. This conversion is a silent truncation, there are no warnings or error messages. The Name type is defined as follows -

    /*
     * Representation of a Name: effectively just a C string, but null-padded to
     * exactly NAMEDATALEN bytes.  The use of a struct is historical. 
     */ 
    typedef struct nameData
    {
        char data[NAMEDATALEN];
    } NameData;
    typedef NameData *Name;

This effectively gives us a max label name length of NAMEDATALEN - 1.

    /*
     * Maximum length for identifiers (e.g. table names, column names,
     * function names).  Names actually are limited to one fewer byte than this, 
     * because the length must include a trailing zero byte. 
     * 
     * This should be at least as much as NAMEDATALEN of the database the 
     * applications run against. 
     */
    #define NAMEDATALEN 64

Since there isn't a way to get around this, the code was modified to reflect the usage of NAMEDATALEN for the length of label names. This required modifying the input parameters to be cstrings, for the functions create_vlabel and create_elabel which allows us to tell when NAMEDATALEN has been exceeded.

Additionally, the function is_valid_label was renamed to is_valid_label_name for consistency.

Regression tests were updated and added.

…EN (apache#1989)

Fixed the issue with creating a label name close to MAX_LABEL_NAME_LEN. Well,
sort of.

The issue here is that a label name is the name of a relation in PostgreSQL.
While the relation name is a char * it is basically converted to a PG type Name
when it is used to create a relation. This conversion is a silent truncation,
there are no warnings or error messages. The Name type is defined as follows -

    /*
     * Representation of a Name: effectively just a C string, but null-padded to
     * exactly NAMEDATALEN bytes.  The use of a struct is historical.
     */
    typedef struct nameData
    {
        char data[NAMEDATALEN];
    } NameData;
    typedef NameData *Name;

This effectively gives us a max label name length of NAMEDATALEN - 1.

    /*
     * Maximum length for identifiers (e.g. table names, column names,
     * function names).  Names actually are limited to one fewer byte than this,
     * because the length must include a trailing zero byte.
     *
     * This should be at least as much as NAMEDATALEN of the database the
     * applications run against.
     */
    #define NAMEDATALEN 64

Since there isn't a way to get around this, the code was modified to reflect the
usage of NAMEDATALEN for the length of label names. This required modifying the
input parameters to be cstrings, for the functions `create_vlabel` and
`create_elabel` which allows us to tell when NAMEDATALEN has been exceeded.

Additionally, the function `is_valid_label` was renamed to `is_valid_label_name`
for consistency.

Regression tests were updated and added.
@github-actions github-actions bot added PG14 PostgreSQL14 override-stale To keep issues/PRs untouched from stale action labels Jul 30, 2024
@jrgemignani jrgemignani requested a review from eyab July 30, 2024 23:30
@MuhammadTahaNaveed MuhammadTahaNaveed merged commit c941999 into apache:PG14 Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

override-stale To keep issues/PRs untouched from stale action PG14 PostgreSQL14

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants