diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2023-06-08 11:24:31 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2023-06-08 11:24:31 -0400 |
commit | d98ed080bb31fd3d46281127871b7886288686d9 (patch) | |
tree | ce150d089e3d3928ada64c6910f2bae44d0b666e /src/backend/utils/adt/encode.c | |
parent | 378d73ef204d0dcbeab834d52478e8cb90578ab7 (diff) | |
download | postgresql-d98ed080bb31fd3d46281127871b7886288686d9.tar.gz postgresql-d98ed080bb31fd3d46281127871b7886288686d9.zip |
Fix small overestimation of base64 encoding output length.
pg_base64_enc_len() and its clones overestimated the output
length by up to 2 bytes, as a result of sloppy thinking about
where to divide. No callers require a precise estimate, so
this has no consequences worse than palloc'ing a byte or two
more than necessary. We might as well get it right though.
This bug is very ancient, dating to commit 79d78bb26 which
added encode.c. (The other instances were presumably copied
from there.) Still, it doesn't quite seem worth back-patching.
Oleg Tselebrovskiy
Discussion: https://postgr.es/m/f94da55286a63022150bc266afdab754@postgrespro.ru
Diffstat (limited to 'src/backend/utils/adt/encode.c')
-rw-r--r-- | src/backend/utils/adt/encode.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c index b92191de81e..e5ac3ad23df 100644 --- a/src/backend/utils/adt/encode.c +++ b/src/backend/utils/adt/encode.c @@ -385,7 +385,7 @@ static uint64 pg_base64_enc_len(const char *src, size_t srclen) { /* 3 bytes will be converted to 4, linefeed after 76 chars */ - return ((uint64) srclen + 2) * 4 / 3 + (uint64) srclen / (76 * 3 / 4); + return ((uint64) srclen + 2) / 3 * 4 + (uint64) srclen / (76 * 3 / 4); } static uint64 |