Issue Details (XML | Word | Printable)

Key: CORE-2582
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Claudio Valderrama C.
Reporter: Claudio Valderrama C.
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Infinity from UDF should be trapped by the engine

Created: 05/Aug/09 04:02 AM   Updated: 28/Jul/11 09:43 AM
Component/s: None
Affects Version/s: 2.5 Beta 1, 2.5 Beta 2
Fix Version/s: 2.5 RC1

Time Tracking:
Not Specified

Environment: Windows XP
Issue Links:
Relate
 

Planning Status: Unspecified


 Description  « Hide
This is related to CORE-2581 Infinity should not escape from the engine
In only tested FB2.5, but maybe FB2.1 behaves the same.
In Windows, there's a __try/__catch block around UDF execution to trap several special conditions. Normally the answer from these conditions is engine shutdown.
I think that in case of overflow, we don't need to panic. We simply need to convert it to an exception about FP overflow.
But I wonder why the protection block used by the Windows build is not working: it should invoke ISC_exception_post() in isc_sync.cpp.

SQL> declare external function dPower
CON> double precision by descriptor, double precision by descriptor,
CON> double precision by descriptor
CON> returns parameter 3
CON> entry_point 'power' module_name 'fbudf';
SQL> select dpower(10e+110, 3) from rdb$database;

                 DPOWER
=======================
               Infinity


C.


 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dmitry Yemanov added a comment - 05/Aug/09 05:35 AM
As far as I can see, the CRT function POW() used in that UDF simply doesn't throw any exception, so there's nothing to catch.

Claudio Valderrama C. added a comment - 05/Aug/09 06:00 AM
In this case, Infinity will have to be detected in fun.epp directly.

Claudio Valderrama C. added a comment - 06/Aug/09 06:58 AM
Given these declarations:

DECLARE EXTERNAL FUNCTION DPOWER
DOUBLE PRECISION BY DESCRIPTOR, DOUBLE PRECISION BY DESCRIPTOR, DOUBLE PRECISION BY DESCRIPTOR
RETURNS PARAMETER 3
ENTRY_POINT 'power' MODULE_NAME 'fbudf';

DECLARE EXTERNAL FUNCTION XASIN
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'IB_UDF_asin' MODULE_NAME 'ib_udf';

DECLARE EXTERNAL FUNCTION XDIV
INTEGER, INTEGER
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'IB_UDF_div' MODULE_NAME 'ib_udf';

the expected answer from the engine is:

SQL> select dpower(1e120, 3) from rdb$database;

                 DPOWER
=======================
Statement failed, SQLSTATE = 39000
expression evaluation not supported
-Floating point overflow in result from UDF DPOWER
SQL> select xasin(2) from rdb$database;

                  XASIN
=======================
Statement failed, SQLSTATE = 39000
expression evaluation not supported
-Invalid floating point value returned by UDF XASIN
SQL> show functions;
       DPOWER XASIN
       XDIV
SQL> select xdiv(10, 0) from rdb$database;

                   XDIV
=======================
Statement failed, SQLSTATE = 39000
expression evaluation not supported
-Floating point overflow in result from UDF XDIV

Pavel Cisar added a comment - 28/Jul/11 09:43 AM
QA test added.