Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash occurs when use SIMILAR TO #6854

Closed
pavel-zotov opened this issue Jun 14, 2021 · 3 comments
Closed

Crash occurs when use SIMILAR TO #6854

pavel-zotov opened this issue Jun 14, 2021 · 3 comments

Comments

@pavel-zotov
Copy link

Consider following script:

 set bail on;
 set list on;
 set names utf8;
 shell del c:\temp\tmp4test.fdb 2>nul;
 create database 'localhost:c:\temp\tmp4test.fdb' default character set utf8;
 show version;
 
 recreate table test(
    id int generated by default as identity constraint pk_txt primary key
   ,txt varchar(1) character set utf8
 );
 
 insert into test(txt) values('A');
 insert into test(txt) values('B'); ---------------------------------- [ 0 ]
 
 set term ^;
 execute block returns(
      o_id type of column test.id
         ,o_txt type of column test.txt
 ) as
         declare b boolean;
 begin
         for select id, txt from test as cursor c
         do begin
             o_id = c.id;
                 o_txt = c.txt;
             suspend;
                 begin
                         b = c.txt similar to 'Ⱥ{0,1}'; ------------ [ 1 ]
                         --b = c.txt similar to 'A{0,1}'; ---------------- [ 2 ]
                 when any do
                         begin
                                 --exception; -------------------------------- [ 3 ]
                         end
                 end
         end
 end
 ^
 set term ;^
 quit;

If we run it on WI-V3.0.8.33473 then FB will crash (stack-trace was created and sent to Adriano et al.)
If we comment out line marked as [ 1 ] and uncomment line [ 2 ], then script finished OK.
If we revert previous state ( make [1] uncommented and [2] commented out) but do uncomment line marked as [ 3 ] then output will be:

 O_ID 1
 O_TXT A
 
 Statement failed, SQLSTATE = 42000
 Invalid SIMILAR TO pattern
 -At block line: 13, col: 4
 -At block line: 17, col: 5

Finally, if we add to the table only ONE row (i.e. comment out, for example, line marked as [ 0 ] ) then test finished OK (no crash).

PS
Problem was found during implementing test for GH-5534. Ticket was created after Adriano request.

@pavel-zotov
Copy link
Author

PS. FB 4.x and 5.x not affected. Only 3.x has such problem.

@asfernandes
Copy link
Member

PS. FB 4.x and 5.x not affected. Only 3.x has such problem.

FB 4.x and 5.x is also affected when a really wrong pattern is used (similar to 'A{X,1}')

@asfernandes
Copy link
Member

The crash is also possible with problematic LIKE:

execute block returns(
    o_id type of column test.id,
    o_txt type of column test.txt
) as
    declare b boolean;
begin
    for select id, txt from test as cursor c
    do
    begin
        o_id = c.id;
        o_txt = c.txt;
        suspend;

        begin
            b = c.txt like '\' escape '\';
            when any do
            begin
            end
        end
    end
end!

asfernandes added a commit that referenced this issue Jun 14, 2021
…pattern

that contains non-ascii character with suppressed exception handling
(or "Invalid SIMILAR TO pattern" raises otherwise).
asfernandes added a commit that referenced this issue Jun 14, 2021
…pattern

that contains non-ascii character with suppressed exception handling
(or "Invalid SIMILAR TO pattern" raises otherwise).
@pavel-zotov pavel-zotov changed the title Crash occurs when use SIMILAR TO and compare string with pattern that contains non-ascii character with suppressed exception handling (or "Invalid SIMILAR TO pattern" raises otherwise) Crash occurs when use SIMILAR TO Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment