Re: [PATCH] pgcrypto: Fix sha-crypt rounds= values that do not fit in int (BUG #19743)

From: Prashant Chinnam <crprashant(at)hotmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: Takeshi Ideriha <iderihatakeshi(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] pgcrypto: Fix sha-crypt rounds= values that do not fit in int (BUG #19743)
Date: 2026-10-27 18:40:38
Message-ID: SN7P223MB060026C7620805ECE34AB331DD602@SN7P223MB0600.NAMP223.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Chao,

> Another thing the patch does is change the NOTICE message
> to print the original input string, which is good in most
> cases. A small concern is: what if the input string is
> unreasonably long? Maybe we should cap the maximum length
> of the printed string?

Good catch, thank you. I checked how far a token can
actually get: nothing on the way in bounds it. pg_crypt()
passes the salt text to px_crypt_shacrypt() unchecked, and
the only length limit in that function,
PX_SHACRYPT_SALT_MAX_LEN, applies to the salt proper, after
the rounds token. Measured on the v2 build, a token of
10000 digits produces a NOTICE of 10076 characters.

Attached is v3, which caps the printed token at 32
characters and appends "..." when it was truncated. 32 is
more than an int64 literal, sign included, can ever need,
so every value a strtoi64() result can hold still prints
in full; only hand-made overlong tokens are cut. With the
cap, the same 10000-digit token now produces a NOTICE of
111 characters. The parsing and clamping do not change,
the comparison battery output is identical to v2, and a
regression test with a 10000-character token is included;
the pgcrypto suite passes 25/25 (and the new test fails
against v2's code, on exactly the new NOTICE line).

Takeshi -- Cc'ing you because the %.*s form was yours;
the cap only limits how much of the token gets echoed.

Testing was done with AI assistance.

Regards,
Prashant Chinnam

Attachment Content-Type Size
v3-0001-pgcrypto-Fix-sha-crypt-rounds-values-that-do-not-fit.patch application/octet-stream 31.0 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2026-10-27 18:44:58 Fix stale relcache fields for TOAST indexes during REINDEX CONCURRENTLY
Previous Message Greg Burd 2026-10-27 17:56:32 Re: Let an ordering index scan hand its ORDER BY value to the target list