Skip to content

Fatal error when decoding an array with a NULL value in it #141

@vzsg

Description

@vzsg

Apparently, Postgres encodes NULL values inside arrays in a way that PostgreSQLDataDecoder does not anticipate. In this case, the byte count of the value is -1, which causes this line called from here to explode with a friendly error:

Fatal error: Can't form Range with upperBound < lowerBound


While this originally was discovered by using the array_agg function combined with left joins (which triggers this weird behavior), there is a much simpler reproduction:

conn.raw("SELECT ARRAY[NULL, 'foo', NULL, 'bar'] AS arr")
    .all(decoding: SimpleArray.self)

where SimpleArray is defined as:

struct SimpleArray: Decodable {
    let arr: [String?]
}

The issue was discovered with Vapor 3 / Postgres (driver) 1.4.1.

V4 doesn't seem to be affected as array decoding is not implemented at all at the time of writing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions