Skip to content

Commit 903aaf0

Browse files
Fix body_buffer overflow for int2 in columnar_result_set_row (#9779)
Flagged by LLM Fuzzer: https://github.com/timescale/timescaledb/actions/runs/25680328237
1 parent f50906a commit 903aaf0

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

tsl/src/nodes/vector_agg/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ columnar_result_init_for_type(ColumnarResult *columnar_result,
123123
{
124124
Assert(columnar_result->type > 0);
125125
columnar_result->allocated_body_bytes =
126-
pad_to_multiple(64, 1 + columnar_result->type * nrows);
126+
pad_to_multiple(64, sizeof(Datum) + columnar_result->type * nrows);
127127
}
128128

129129
columnar_result->body_buffer = MemoryContextAllocZero(batch_state->per_batch_context,

tsl/test/expected/vector_agg_memory.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,39 @@ select * from log where (
115115
n | bytes | a | b | c | d | e | f
116116
---+-------+---+---+---+---+---+---
117117

118+
-- Test body_buffer overflow for int2 type, it was flagged by LLM Fuzzer.
119+
CREATE TABLE t_int2_repro (
120+
time timestamptz NOT NULL,
121+
a int2 NOT NULL,
122+
b int2 NOT NULL
123+
);
124+
SELECT table_name FROM create_hypertable('t_int2_repro', 'time', chunk_time_interval => interval '1 year');
125+
table_name
126+
--------------
127+
t_int2_repro
128+
129+
-- Insert exactly 30 rows into a single chunk, body_buffer will be set to 30*2 + 8(size of Datum) padded to 64 bytes.
130+
INSERT INTO t_int2_repro
131+
SELECT '2020-01-01'::timestamptz + i * '1 hour'::interval,
132+
(i % 100)::int2,
133+
(i % 50)::int2
134+
FROM generate_series(1, 30) i;
135+
ALTER TABLE t_int2_repro SET (
136+
timescaledb.compress,
137+
timescaledb.compress_orderby = 'time'
138+
);
139+
SELECT count(compress_chunk(c)) FROM show_chunks('t_int2_repro') c;
140+
count
141+
-------
142+
1
143+
144+
-- This triggers vector_slot_evaluate_function with int2pl (int2 + int2 -> int2),
145+
-- which calls columnar_result_set_row with type=2.
146+
-- Should not see warning on memcpy overflow.
147+
SELECT sum(a + b) FROM t_int2_repro;
148+
sum
149+
-----
150+
930
151+
152+
drop table t_int2_repro cascade;
118153
reset max_parallel_workers_per_gather;

tsl/test/sql/vector_agg_memory.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,32 @@ select * from log where (
126126
select regr_slope(bytes, n) > 0.01 from log
127127
);
128128

129+
-- Test body_buffer overflow for int2 type, it was flagged by LLM Fuzzer.
130+
CREATE TABLE t_int2_repro (
131+
time timestamptz NOT NULL,
132+
a int2 NOT NULL,
133+
b int2 NOT NULL
134+
);
135+
SELECT table_name FROM create_hypertable('t_int2_repro', 'time', chunk_time_interval => interval '1 year');
136+
137+
-- Insert exactly 30 rows into a single chunk, body_buffer will be set to 30*2 + 8(size of Datum) padded to 64 bytes.
138+
INSERT INTO t_int2_repro
139+
SELECT '2020-01-01'::timestamptz + i * '1 hour'::interval,
140+
(i % 100)::int2,
141+
(i % 50)::int2
142+
FROM generate_series(1, 30) i;
143+
144+
ALTER TABLE t_int2_repro SET (
145+
timescaledb.compress,
146+
timescaledb.compress_orderby = 'time'
147+
);
148+
SELECT count(compress_chunk(c)) FROM show_chunks('t_int2_repro') c;
149+
150+
-- This triggers vector_slot_evaluate_function with int2pl (int2 + int2 -> int2),
151+
-- which calls columnar_result_set_row with type=2.
152+
-- Should not see warning on memcpy overflow.
153+
SELECT sum(a + b) FROM t_int2_repro;
154+
155+
drop table t_int2_repro cascade;
156+
129157
reset max_parallel_workers_per_gather;

0 commit comments

Comments
 (0)