Changeset: 1f769122444c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1f769122444c
Added Files:
sql/test/BugTracker-2026/Tests/8072-insert-nr-overflow.test
Modified Files:
monetdb5/modules/atoms/str.c
sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:
fixed issue # 8072, check for overflow
diffs (82 lines):
diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -1751,10 +1751,8 @@ str_insert(str *buf, size_t *buflen, con
SQLSTATE(42000)
"The number of characters for insert function must be
non negative");
if (strt < 0) {
- if (-strt <= l1)
- strt = l1 + strt;
- else
- strt = 0;
+ lng pos = (lng) l1 + strt;
+ strt = pos > 0 ? (int) pos : 0;
}
if (strt > l1)
strt = l1;
@@ -1765,7 +1763,9 @@ str_insert(str *buf, size_t *buflen, con
if (strt > 0)
v = UTF8_strncpy(v, s, strt);
v = stpcpy(v, s2);
- if (strt + l < l1)
+ /* l may be INT_MAX, so avoid computing strt + l before checking
+ * whether the requested range reaches past the end of the string */
+ if (l < l1 - strt)
strcpy(v, UTF8_strtail(s, strt + l));
return MAL_SUCCEED;
}
diff --git a/sql/test/BugTracker-2026/Tests/8072-insert-nr-overflow.test
b/sql/test/BugTracker-2026/Tests/8072-insert-nr-overflow.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2026/Tests/8072-insert-nr-overflow.test
@@ -0,0 +1,42 @@
+# insert(s1, pos, nr, s2) must not overflow while computing pos + nr
+
+query T
+SELECT insert('abcdef', 2, 2147483645, 'XY')
+----
+abXY
+
+query T
+SELECT insert('abcdef', 2, 2147483646, 'XY')
+----
+abXY
+
+query T
+SELECT insert('abcdef', 1, 2147483647, 'XY')
+----
+aXY
+
+query T
+SELECT insert('abcdef', 2147483647, 2147483647, 'XY')
+----
+abcdefXY
+
+query T rowsort
+SELECT insert(s, 2, n, 'XY') FROM (VALUES ('abcdef', 2147483646), ('abcdef',
2147483647)) AS t(s, n)
+----
+abXY
+abXY
+
+query T
+SELECT insert('abcdef', 2, 100, 'XY')
+----
+abXY
+
+query T
+SELECT insert('abcdef', -2, 2147483647, 'XY')
+----
+abcdXY
+
+query T
+SELECT insert('abcdef', -7, 1, 'XY')
+----
+XYbcdef
diff --git a/sql/test/BugTracker-2026/Tests/All
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -232,3 +232,4 @@ KNOWNFAIL?8010-first_value-last_value-pa
8068-pipeline-limit-slice-join
8070-sum-constant-drops-groupby-aggregates
8071-uncommitted-update-delta-scan
+8072-insert-nr-overflow
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]