Skip to content

[CBRD-27216] Fix int32 overflow in REPEAT result size (11.4) - #7704

Merged
kangmin5505 merged 3 commits into
CUBRID:release/11.4from
kangmin5505:CBRD-27216-11.4
Aug 18, 2026
Merged

[CBRD-27216] Fix int32 overflow in REPEAT result size (11.4)#7704
kangmin5505 merged 3 commits into
CUBRID:release/11.4from
kangmin5505:CBRD-27216-11.4

Conversation

@kangmin5505

@kangmin5505 kangmin5505 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

http://jira.cubrid.org/browse/CBRD-27216

Purpose

  • REPEAT(str, n) 의 결과 byte size 가 int32 overflow 되어 cub_server 가 crash. 멀티바이트(UTF-8) 컬럼이면 일반 SELECT 로 재현.

Implementation

Remarks

  • oversize error path 에서 dummy 를 해제하는 pr_clear_value 를 추가했다. 이 분기는 int 곱셈 시절 결과가 DB_INT32_MAX 를 넘을 수 없어 도달 불가능했고, 64-bit 곱셈으로 처음 살아났다.

- REPEAT computed its result byte size with a 32-bit multiply, so a large
  result wrapped past the size check and undersized the buffer; the copy loop
  then overran the heap and crashed the server. Widen the multiply to 64-bit
  so the check fires and the statement errors out instead.
- Report the requested byte count as size_t in message 1042, now that it can
  exceed int range.
- An over-limit but non-overflowing result still returns NULL rather than an
  error, kept for MySQL compatibility.

(cherry picked from commit ab1e86e)
@kangmin5505 kangmin5505 self-assigned this Aug 14, 2026
@kangmin5505
kangmin5505 marked this pull request as ready for review August 14, 2026 02:55
Copilot AI lite review requested due to automatic review settings August 14, 2026 02:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a server-crash bug caused by 32-bit integer overflow when computing the result byte size for REPEAT(str, n) (notably reproducible with multibyte/UTF-8 strings), and aligns the related error message formatting with size_t-sized values.

Changes:

  • Prevents int32 wraparound in db_string_repeat size calculation by promoting the multiplication to 64-bit before overflow checking.
  • Updates ER_QPROC_STRING_SIZE_TOO_BIG reporting call sites to pass the required-size argument as size_t.
  • Updates message 1042 format specifier from %d to %zu (Korean/English catalogs) to correctly print size_t.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/query/string_opfunc.c Promotes src_size * count_i to 64-bit before overflow checking and passes required sizes as size_t to match updated message formatting.
msg/ko_KR.utf8/cubrid.msg Updates message 1042 to print required bytes using %zu.
msg/en_US.utf8/cubrid.msg Updates message 1042 to print required bytes using %zu.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'upstream/r..." | Re-trigger Greptile

Comment thread src/query/string_opfunc.c
db_string_make_empty_typed_string leaves dummy holding an allocated
buffer, and the ER_QPROC_STRING_SIZE_TOO_BIG return is the only exit
that does not clear it. The 64-bit multiply makes that branch reachable
for the first time -- it was unreachable while the product was computed
in int, since an int result can never exceed DB_INT32_MAX.
@kangmin5505
kangmin5505 merged commit 7654942 into CUBRID:release/11.4 Aug 18, 2026
10 checks passed
@kangmin5505
kangmin5505 deleted the CBRD-27216-11.4 branch August 18, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants