Package constants. FB crashes if package body constant is queried

61 views
Skip to first unread message

Pavel Zotov

unread,
Jun 11, 2026, 4:53:10 AMJun 11
to firebird-devel
Consider script:
==========
set bail on;
set list on;
set autoterm on;
set autoddl off; ---------------------------------- [ 0 ]
set keep_tran on;

set echo on;
shell if exist r:\temp\tmp4test.fdb del r:\temp\tmp4test.fdb;
create database 'localhost:r:\temp\tmp4test.fdb' user 'sysdba' password 'masterkey';

create package pg_test as
begin
    -- #################################
    constant PG_HEAD_CONST smallint = 1;
    -- #################################
    procedure sp_test(a_what varchar(4)) returns(o smallint);
    function fn_test(a_what varchar(4)) returns smallint;
end
;
recreate package body pg_test as
begin
    -- #################################
    constant PG_BODY_CONST smallint = -1;
    -- #################################
    procedure sp_test(a_what varchar(4)) returns(o smallint) as
    begin
        o = iif(a_what = 'head', pg_head_const, pg_body_const);
        suspend;
    end

    function fn_test(a_what varchar(4)) returns smallint as
    begin
        return iif(a_what = 'head', pg_head_const, pg_body_const);
    end
end
;
commit;
-- connect 'localhost:r:\temp\tmp4test.fdb' user 'sysdba' password 'masterkey';

execute block as
begin
    rdb$set_context('USER_SESSION', 'CHECKED_CONST_TYPE', 'head');
    -- rdb$set_context('USER_SESSION', 'CHECKED_CONST_TYPE', 'body'); -------------- [ 1 ]
end
;
select p.o as get_pkg_head_const_1  from pg_test.sp_test(rdb$get_context('USER_SESSION', 'CHECKED_CONST_TYPE')) as p rows 1;

select pg_test.fn_test(rdb$get_context('USER_SESSION', 'CHECKED_CONST_TYPE')) as get_pkg_head_const_2 from rdb$database;

select pg_test.fn_test(rdb$get_context('USER_SESSION', 'CHECKED_CONST_TYPE')) as get_pkg_head_const_3
from pg_test.sp_test(rdb$get_context('USER_SESSION', 'CHECKED_CONST_TYPE')) rows 1;

==========

Note on statement marked as [ 0 ] - it is mandatory to reproduce problem.
This script completes fine.

Now UNcomment statement marked as [ 1 ].
Script will cause FB crash (can be seen on any of queries with "get_pkg_head_const_1" ... "get_pkg_head_const_3" column names).

Checked on 6.0.0.2002-b408a05.
This is link to the dump, stack trace, firebird.conf / .log and FB snapshot.

PS.
It seems that crash caused by #e588f9ea
/*
    Fix calling reload twice for package constants and improve hash calculation (#9045)
    * Fix calling reload twice for package constants and improve hash calculation
    * Do not hash value for package constant
    * Fix incorrect DSC_SIZE_TO_HASH calculation
    * Add static_assert for correct layout of dsc for hash
*/
(before 6.0.0.1995-e588f9e output was "HY000 / statement format outdated')












Artyom Abakumov

unread,
Jun 15, 2026, 5:27:20 AMJun 15
to firebird-devel
Thanks for providing a reproducing case. I fixed the main issue in the package code, but there's another problem in the engine (EXE_assignment). I'm not very familiar with that part of the code, so it will take some time to figure out what the problem is.
четверг, 11 июня 2026 г. в 11:53:10 UTC+3, Pavel Zotov:

Artyom Abakumov

unread,
Jun 16, 2026, 5:36:34 AMJun 16
to firebird-devel
The fix is ready: https://github.com/FirebirdSQL/firebird/pull/9065

понедельник, 15 июня 2026 г. в 12:27:20 UTC+3, Artyom Abakumov:

Pavel Zotov

unread,
Jun 20, 2026, 7:43:38 AMJun 20
to firebird-devel
AFAIU, it is not yet committed ?
Because my script still cause FB crash (checkd on 6.0.0.2022-db592b6)


Artyom Abakumov

unread,
Jun 20, 2026, 8:58:12 AMJun 20
to firebird-devel

AFAIU, it is not yet committed ?
Because my script still cause FB crash (checkd on 6.0.0.2022-db592b6)
 
Unfortunately, none of the Firebird developers have looked at the pull request yet. 

Pavel Zotov

unread,
Jul 1, 2026, 9:21:05 AM (6 days ago) Jul 1
to firebird-devel

Checked 6.0.0.2050-09246e5 --all fine.
Test has been commited




Reply all
Reply to author
Forward
0 new messages