-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
Conversion of text with '\0' to DECFLOAT without errors. #7599
Comments
BTW diags in case of integer is also rather far from ideal |
Alex, I rewrote decFloatFromString to work with a range of characters, and I seem to have found a few pointer issues. If you haven't started dealing with this issue yet, you can wait while I finish and provide more information. |
Have not. It will be great. |
About a problem with pointers. I'll try to explian a problem as simple as possible :) Sample query: select cast('-0000000000000000000000000000000000000000000000000000000000000000000000000000000.E+7000' as DECFLOAT(34))
from rdb$database decFinalize function receives 'num' with this data: As you can see, lsd<msd and both members are pointing to uninitialized memory. msd is pointing on MOST significant digit decFinalize expectes that num contains at least one digit - it means that msd<=lsd Look at this code of decFinalize: firebird/extern/decNumber/decCommon.c Lines 261 to 269 in 5ed9d76
It reads this bad data in line 265 without any preliminary checks (NUMISSPECIAL does not check these pointers). This situation is occurring by mistake in decFloatFromString firebird/extern/decNumber/decCommon.c Lines 906 to 917 in 5ed9d76
This cycle must keep at least one (the last) zero symbol but it is ignoring all them. The reason for it - the last '.' I rewrote this code: // [This is a rare and unusual case; arbitrary-length input]
// strip leading zeros [but leave final 0 if all 0's]
{
char* cfirst2=NULL;
for (; cfirst<=clast; cfirst++) {
if (*cfirst == '.') continue; // [ignore]
cfirst2=cfirst; // let's save the position of this digit
if (*cfirst!='0') break; // done
assert(digits>0);
digits--; // 0 stripped
} // cfirst
assert(cfirst2 != NULL);
assert(cfirst2 <= clast);
if(clast<cfirst) { // all the symbols are ZEROs
assert(digits==0);
digits=1;
} else {
assert(digits>0);
}
cfirst=cfirst2;
} // local - at least one leading 0 Now decFinalize receives the correct presentation of 'num': I ran my others tests - it seems all is ok, too. |
The second problem with pointers lives in decFinalize function and I am not sure that I am right. Look at this code: firebird/extern/decNumber/decCommon.c Lines 455 to 469 in 5ed9d76
Lines with problem: firebird/extern/decNumber/decCommon.c Lines 467 to 468 in 5ed9d76
buffer it is a local memory and can be freed/reused after this block. I think this 'buffer' must be declared at the top level of decFinalize. |
Confirm both problems - with pointers and illegally located buffer. Can you prepare PR? |
Yes, no problems. For FB4 and HEAD. |
Can I add asserts (native asserts, not fb_asserts)? |
Asserts were added.
…lize was corrected
If asserts are already used in original decfloat library code - yes, certainly. If not - I think it's better to avoid them in order to follow code style of the project. Provided you are not going to rework all code - hope not :) |
Alex, applyed PR does not fix this problem :) For fix of this issue it is need
|
On 5/30/23 14:39, Dmitry Kovalenko wrote:
Detect '\0' before the call of fromString function
That's what I was going to do initially...
Will reopen an issue.
|
Also raise conversion error instead indeterminant decfloat error and output symbols < 32 in \xDD format. Single \ replaced with \. |
Using new decFloatFromString_fb function instead decFloatFromString. New code was added into decCommon_fb.c file.
I think decFloatFromString_fb can be upgraded to return an additional info about a bad position and this information can be used for creating a detail message. At the next stage, of course, not right now. |
That makes sense provided all conversion errors are accompanied with error column info. |
…out errors; ensure better backward compatibility
(cherry picked from commit fa6f919)
…out errors; ensure better backward compatibility (cherry picked from commit 3b9d57b)
The text was updated successfully, but these errors were encountered: