escape vs. bytea in config - Mailing list pgsql-general

From Mathias Mayrhofer
Subject escape vs. bytea in config
Date
Msg-id ab608b9b-862b-c773-ea6f-298b9da6a898@mtmayr.com
Whole thread Raw
Responses Re: escape vs. bytea in config
Re: escape vs. bytea in config
List pgsql-general

Dear Supportlist,

I came across the "bytea_output" configuration variable inside postgresql.conf. It seems to be affecting the "digest" function, but in a way I cannot understand.

When my postgresql 14 server executes the digest function, it considers the "bytea_output" variable, but the output of the function is *NOT* the same as the "encode" function. It differs only slightly.

Please have a view of the following two conditions: First with "bytea_output = hex", second with "bytea_output = escape". In both ways the result differs, which leads to my password-comparison to turn out false.

Regards,
Mathias


-- /etc/postgresql/14/main/postgresql.conf
-- bytea_output = 'hex'

db=> select digest('mtmayr', 'sha256');
┌────────────────────────────────────────────────────────────────────┐
│                               digest                               │
├────────────────────────────────────────────────────────────────────┤
│ \xbf1995dd67c794df2de75983acd41f66c750682ab75ca3a935538b575884fd47 │
└────────────────────────────────────────────────────────────────────┘

db=> select encode(digest('mtmayr', 'sha256'), 'hex');
┌──────────────────────────────────────────────────────────────────┐
│                              encode                              │
├──────────────────────────────────────────────────────────────────┤
│ bf1995dd67c794df2de75983acd41f66c750682ab75ca3a935538b575884fd47 │
└──────────────────────────────────────────────────────────────────┘


-- /etc/postgresql/14/main/postgresql.conf
-- bytea_output = 'escape'

db=> select encode(digest('mtmayr', 'sha256'), 'escape');
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│                                           encode                                           │
├────────────────────────────────────────────────────────────────────────────────────────────┤
│ \277\x19\225\335g\307\224\337-\347Y\203\254\324\x1Ff\307Ph*\267\\\243\2515S\213WX\204\375G │
└────────────────────────────────────────────────────────────────────────────────────────────┘

db=> select digest('mtmayr', 'sha256');
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│                                           digest                                           │
├────────────────────────────────────────────────────────────────────────────────────────────┤
│ \277\031\225\335g\307\224\337-\347Y\203\254\324\037f\307Ph*\267\\\243\2515S\213WX\204\375G │
└────────────────────────────────────────────────────────────────────────────────────────────┘

--    ^^  differences                             ^^^^

-- 
/\/\athias /\/\ayrhofer

pgsql-general by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: Multiple core dump errors are thrown by initdb when Huge pages are enabled in OS and huge_pages is set to “off” in postgresql.conf.sample in Kubernetes.
Next
From: Laurenz Albe
Date:
Subject: Re: escape vs. bytea in config