Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2023-06-08 15:24:31 +0000
committerTom Lane2023-06-08 15:24:31 +0000
commitd98ed080bb31fd3d46281127871b7886288686d9 (patch)
treece150d089e3d3928ada64c6910f2bae44d0b666e /src/common/base64.c
parent378d73ef204d0dcbeab834d52478e8cb90578ab7 (diff)
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/common/base64.c')
-rw-r--r--src/common/base64.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/common/base64.c b/src/common/base64.c
index 2943ac76520..ec4eb49382c 100644
--- a/src/common/base64.c
+++ b/src/common/base64.c
@@ -224,7 +224,7 @@ int
pg_b64_enc_len(int srclen)
{
/* 3 bytes will be converted to 4 */
- return (srclen + 2) * 4 / 3;
+ return (srclen + 2) / 3 * 4;
}
/*