Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vzsg opened this issue Sep 8, 2019 · 0 comments
Closed

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

vzsg opened this issue Sep 8, 2019 · 0 comments

Comments

@vzsg
Copy link
Member

vzsg commented Sep 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant