Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd98ed08

Browse files
committed
Fix small overestimation of base64 encoding output length.
pg_base64_enc_len() and its clones overestimated the outputlength by up to 2 bytes, as a result of sloppy thinking aboutwhere to divide. No callers require a precise estimate, sothis has no consequences worse than palloc'ing a byte or twomore than necessary. We might as well get it right though.This bug is very ancient, dating to commit79d78bb whichadded encode.c. (The other instances were presumably copiedfrom there.) Still, it doesn't quite seem worth back-patching.Oleg TselebrovskiyDiscussion:https://postgr.es/m/f94da55286a63022150bc266afdab754@postgrespro.ru
1 parent378d73e commitd98ed08

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

‎contrib/pgcrypto/pgp-armor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pg_base64_enc_len(unsigned srclen)
165165
/*
166166
* 3 bytes will be converted to 4, linefeed after 76 chars
167167
*/
168-
return (srclen+2)*4/3+srclen / (76*3 /4);
168+
return (srclen+2) /3*4+srclen / (76*3 /4);
169169
}
170170

171171
staticunsigned

‎src/backend/utils/adt/encode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static uint64
385385
pg_base64_enc_len(constchar*src,size_tsrclen)
386386
{
387387
/* 3 bytes will be converted to 4, linefeed after 76 chars */
388-
return ((uint64)srclen+2)*4/3+ (uint64)srclen / (76*3 /4);
388+
return ((uint64)srclen+2) /3*4+ (uint64)srclen / (76*3 /4);
389389
}
390390

391391
staticuint64

‎src/common/base64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int
224224
pg_b64_enc_len(intsrclen)
225225
{
226226
/* 3 bytes will be converted to 4 */
227-
return (srclen+2)*4/3;
227+
return (srclen+2) /3*4;
228228
}
229229

230230
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp