DECLARED TEMP TABLE. Bugcheck when recursive calls are used and integer overflow occurs

14 views
Skip to first unread message

Pavel Zotov

unread,
Jul 28, 2026, 7:18:04 AM (6 days ago) Jul 28
to firebird-devel
Please consider script:
===========
set bail on;
set list on;
set autoterm on;
shell if exist r:\temp\tmp4test.fdb del r:\temp\tmp4test.fdb;
create database 'localhost:r:\temp\tmp4test.fdb' user 'sysdba' password 'masterkey';
commit;
create global temporary table t_accumulator(id smallint, f int128) on commit delete rows;
create or alter procedure sp_recur(i smallint) returns(o int128, u int128) as
    -- declare temporary table t_accumulator(id smallint, f int128); ------------ [ 1 ]
begin
    if ( i > 1 ) then
        begin
            o = i * (select o from sp_recur( :i - 1 ));
        end
    else
        begin
            o = i;
        end

    insert into t_accumulator(id, f) values(:i, :o);
    u = (select sum(f) from t_accumulator);
    suspend;

end
;
select p.* from sp_recur(34) p;

===========

It will raise error:
===========
Statement failed, SQLSTATE = 22003
arithmetic exception, numeric overflow, or string truncation
-Integer overflow.  The result of an integer operation caused the most significant bit of the result to carry.
-At procedure "PUBLIC"."SP_RECUR" line: 6, col: 13
===========
 (and this is expected because 34! =~ 2.95E38  -- greater than max(int128) = 2^127 =~ 1.70E38)

Now UNcomment line markled as "[ 1 ] " and repeat.
Bugcheck will raise with following message in the firebird.log:
==========
arithmetic exception, numeric overflow, or string truncation
Integer overflow.  The result of an integer operation caused the most significant bit of the result to carry.
At procedure "PUBLIC"."SP_RECUR" line: 6, col: 13
internal Firebird consistency check (record disappeared (186), file: Savepoint.cpp line: 281)

==========

This is URL to dump, stacktracem firebird.conf, firebird.log and snapshot ( checked on 6.0.0.2097-0592438 ).

Adriano dos Santos Fernandes

unread,
Jul 28, 2026, 8:35:20 PM (5 days ago) Jul 28
to firebir...@googlegroups.com
On 7/28/26 08:18, Pavel Zotov wrote:
> Please consider script:

Fixed.


Adriano

Pavel Zotov

unread,
Jul 29, 2026, 6:40:31 AM (5 days ago) Jul 29
to firebird-devel
Fixed.

Confirmed fix, test has been committed.


 
Reply all
Reply to author
Forward
0 new messages