Package constants. FB crashes if package body constant is queried

10 views
Skip to first unread message

Pavel Zotov

unread,
Jun 11, 2026, 4:53:10 AM (4 days ago) Jun 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')












Reply all
Reply to author
Forward
0 new messages