-
Notifications
You must be signed in to change notification settings - Fork 105
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
c/driver/common/utils.c: tables are found when they should not #1100
Comments
ah...fun. |
at some point I'm going to refactor things into C++ (and hopefully C++17) and then we can just use string_view to compare things sensibly |
@ywc88 might you be able to fix this for now? guess we have to do a bit of arithmetic and strncmp |
As a mitigation, you could also compare the lengths of the strings. Like:
That should at least reduce the chance of false matches, I'm not 100% sure it's a full fix. By the way, the current method of string comparisons is also used in many other functions, it would need some testing to figure out if a fix needs to be applied somewhere else as well. |
Hmm so the ArrowStringView that is the |
After some more testing, I think it works a bit different than stated in the issue text above, my apologies. The bug is still there, the explanation might be slightly different, though. StringView works fine and returns the correct length. The problem lies in the way
The Still, comparing both string lengths should probably help here, e.g. as above: Whether a fix like this is needed in other comparisons, I do not know. I hope this is the correct interpretation now. I ran into this issue by trying to see how certain tests fail, but sometimes they passed where they should not. |
Ah nice find. I think the upfront strlen check makes sense. Should likely be done for all comparisons in the module |
… correctly (#1168) Fixes #1100 Test before fix: ``` Expected equality of these values: AdbcGetObjectsDataGetTableByName(&mock_data, "mock_catalog", "mock_schema", "table_suffix") Which is: 0x16d014ee8 &mock_table_suffix Which is: 0x16d014ea8 arrow-adbc/c/driver/common/utils_test.cc:220: Failure Expected equality of these values: AdbcGetObjectsDataGetColumnByName(&mock_data, "mock_catalog", "mock_schema", "table", "column_suffix") Which is: 0x16d014df8 &mock_column_suffix Which is: 0x16d014d48 arrow-adbc/c/driver/common/utils_test.cc:224: Failure Expected equality of these values: AdbcGetObjectsDataGetConstraintByName(&mock_data, "mock_catalog", "mock_schema", "table", "constraint_suffix") Which is: 0x16d014d08 &mock_constraint_suffix Which is: 0x16d014cc8 [ FAILED ] AdbcGetObjectsData.GetObjectsByName (0 ms) ``` Test after fix: ``` $ ctest Test project arrow-adbc/build Start 1: adbc-driver-common-test 1/2 Test #1: adbc-driver-common-test .......... Passed 0.25 sec Start 2: adbc-driver-sqlite-test 2/2 Test #2: adbc-driver-sqlite-test .......... Passed 0.19 sec 100% tests passed, 0 tests failed out of 2 Label Time Summary: driver-common = 0.25 sec*proc (1 test) driver-sqlite = 0.19 sec*proc (1 test) unittest = 0.43 sec*proc (2 tests) Total Test time (real) = 0.44 sec ```
Certain string matchings fail in
c/driver/common/utils.c
when trying to find a table by name. A loop iterates through all tables and tries to find a match. The matching code is currently:name.data
is a contiguous buffer of table names, likeadbc_pkey_testtest_canceladbc_fkey_test_baseadbc_fkey_testadbc_composite_pk[...]
. Thetable_name
(let's sayadbc_pkey_test
) is now compared to the firstname.size_bytes
of this buffer, which usually works out. If a non-existingtable_name
string is composed of an existing table name plus starting characters of another table, a match can be made where there is none. A correctly matching example is:An example that matches erroneously is:
N.B.: The tables are returned in nondeterministic order, so this might not fail reliably.
Software version: current
main
branch 8a832d6The text was updated successfully, but these errors were encountered: