Skip to content

Segfault when package procedure initializes local variable from parameter #1005

Closed

Description

@rophy

Bug Report

IvorySQL Version

PostgreSQL 18.0 (IvorySQL 5.0) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit

Docker image: ivorysql/ivorysql:5.0-bookworm

OS Version (uname -a)

Linux 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC x86_64 GNU/Linux

Configuration options (config.status --config)

'--prefix=/var/local/ivorysql/ivorysql-5' '--enable-cassert' '--enable-debug' '--enable-rpath' '--with-tcl' '--with-python' '--with-gssapi' '--with-pam' '--with-ldap' '--with-openssl' '--with-libedit-preferred' '--with-uuid=e2fs' '--with-ossp-uuid' '--with-libxml' '--with-libxslt' '--with-perl' '--without-icu'

Current Behavior

The server crashes with a segmentation fault when calling ANY function in a PL/iSQL package that contains a private procedure with a local variable initialized directly from a parameter.

The crash occurs even if the problematic procedure is never called - simply having it defined in the package body is enough to trigger the crash when any other function in the package is invoked.

Expected behavior/code

The package should compile and execute without crashing the server. Local variable initialization from parameters is standard PL/SQL syntax and should work correctly.

Steps to reproduce

  1. Connect to IvorySQL on the Oracle-compatible port (1521)

  2. Create the following package:

CREATE OR REPLACE PACKAGE crash_test IS
  FUNCTION get_info RETURN VARCHAR2;
END;
/

CREATE OR REPLACE PACKAGE BODY crash_test IS
  -- Private procedure with local variable initialized from parameter
  PROCEDURE do_something(p_val IN NUMBER) AS
    v_local NUMBER := p_val;  -- THIS LINE CAUSES THE CRASH
  BEGIN
    NULL;
  END;

  -- Any public function
  FUNCTION get_info RETURN VARCHAR2 IS
  BEGIN
    RETURN 'hello';
  END;
END;
/
  1. Call any function in the package:
SELECT crash_test.get_info();
  1. Server crashes with "server closed the connection unexpectedly"

Workaround: Initialize local variables to constants, then assign from parameters in the procedure body:

PROCEDURE do_something(p_val IN NUMBER) AS
  v_local NUMBER := 0;  -- Initialize to constant
BEGIN
  v_local := p_val;     -- Assign from parameter in body - this works
END;

Additional context that can be helpful for identifying the problem

  • The crash occurs during package instantiation/function invocation, not during compilation
  • The package compiles successfully without errors
  • The problematic procedure does not need to be called - its mere presence in the package body triggers the crash
  • The issue appears to be related to how parameter references in variable initializers are resolved during package loading
  • This affects any package with this pattern, regardless of package complexity
  • Tested on Docker image ivorysql/ivorysql:5.0-bookworm
  • The same SQL executes correctly on Oracle Database 23c Free
    (container-registry.oracle.com/database/free:23.26.0.0-lite), confirming this is valid PL/SQL syntax

Activity

  1. added
    bug
    on Dec 4, 2025
  2. jiaoshuntian commented on Dec 5, 2025

    @jiaoshuntian
    Collaborator

    Thank you for reporting this issue. We will fix it as soon as possible.

  3. added 5 commits that reference this issue on Dec 7, 2025
    29f5ec1
    ccd7ad8
    d23c62a
    6f1a164
    c2aed6a
  4. added a commit that references this issue on Jan 9, 2026
  5. moved this from Backlog to Done in IvorySQL 5.3on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions