-
Notifications
You must be signed in to change notification settings - Fork 109
[CLIENT-4845] Fix user dictionary returning only the first entry of read_info and write_info array of integers #1074
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
Merged
juliannguyen4
merged 36 commits into
dev
from
CLIENT-4845-fix-user-dictionary-only-returning-integers-instead-of-list-of-ints
Jun 3, 2026
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
812f2eb
Add -Werror to setup.py so that all source builds check for warnings.…
juliannguyen4 97d3509
Address bug with read_info. TODO write_info
juliannguyen4 e968c1c
Fix usage of CPython API
juliannguyen4 ef0842e
Finish fixing both read_info and write_info. TODO memory leaks need t…
juliannguyen4 657cbfd
Do more refactoring to make helper functions consistent with convert_…
juliannguyen4 3e97224
fix compiler error
juliannguyen4 dd0d546
Fix syntax err
juliannguyen4 ccfe064
Fix tests not following the api docs
juliannguyen4 66ae7a3
We can remove this declaration in header if nowhere else is using it.
juliannguyen4 51ad3e7
Improve var naming
juliannguyen4 5a68322
Fix error message
juliannguyen4 896d3b8
Make helper function naming more accurate.
juliannguyen4 b4194d6
Add missing as_error_update to convert_nullable_array_of_uint32_to_py…
juliannguyen4 11c7e34
Fix c syntax. This happened because my compiler path became unset in …
juliannguyen4 625b4ed
Create a helper function that converts an array of any type to a Pyth…
juliannguyen4 09af384
Fix improper usage of Py_BuildValue
juliannguyen4 a2cf9e3
format_str should be writable..
juliannguyen4 f242f2d
Just verified that client fails to compile in macOS with -Werror. Onl…
juliannguyen4 9daaac0
Mark as TODO so this doesn't get lost
juliannguyen4 9a17540
Merge branch 'CLIENT-4868-cicd-fix-regression-where-smoke-tests-no-lo…
juliannguyen4 52b68ba
Use void pointer parameter to accept an array containing any type. I …
juliannguyen4 22d0802
Fix invalid cast.
juliannguyen4 8e4deca
Since array is a 2D (flat) array of const chars, fix the logic for it…
juliannguyen4 5febb3f
Fix incorrect format specifier. l is for signed long int
juliannguyen4 4e7fcdb
Fix invalid cast. unsigned long is 64-bit size in linux.
juliannguyen4 2ff81de
Merge remote-tracking branch 'origin/dev' into CLIENT-4845-fix-user-d…
juliannguyen4 b1d4531
convert_nullable_array_to_py_optional_list is only used in conversion…
juliannguyen4 806eb5d
Add helpful docstring
juliannguyen4 0219668
Add comments for clarity. Reorder switch cases in increasing numeric …
juliannguyen4 f1c02d3
Fix potential reference count leak when conns_in_use is returned in a…
juliannguyen4 c57b966
use macro to reduce code repetition for error handling
juliannguyen4 22cace4
Improve var naming a bit.
juliannguyen4 4d47bbd
use case level scoping to create local vars with the same name across…
juliannguyen4 8a194d4
Address Windows compiler error by fixing pointer arithmetic syntax.
juliannguyen4 3b5b012
Promote uint32_t value to become unsigned long to be safe.
juliannguyen4 dd94e56
Merge remote-tracking branch 'origin/dev' into CLIENT-4845-fix-user-d…
juliannguyen4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI picked this up, looks like it is worth using
Ihere.Py_BuildValue format 'k' doesn't match the uint32_t argument
In convert_nullable_array_to_py_optional_list:
case 'k': {
uint32_t element = ((uint32_t *)array)[i];
py_element = Py_BuildValue(format_str, element); // format_str == "k"
break;
}
read_info and write_info are uint32_t* (confirmed in as_admin.h: uint32_t* read_info;, uint32_t* write_info;), and uint32_t is unsigned
int on all target platforms. But the 'k' format code tells Py_BuildValue to read an unsigned long via va_arg.
This is a varargs type mismatch (undefined behavior):
zero-extends, so it usually works by luck — but it's relying on UB.
zeroed, so va_arg(ap, unsigned long) can read garbage in the high word → wrong read_info/write_info integers. They build and ship aarch64
wheels, so this is a genuine cross-platform correctness risk, not purely theoretical.
Fix: use the 'I' (unsigned int) format code for uint32_t:
case 'I': {
uint32_t element = ((uint32_t *)array)[i];
py_element = Py_BuildValue(format_str, element);
break;
}
(and pass 'I' instead of 'k' from as_user_info_to_pyobject). Alternatively keep 'k' but cast the argument: Py_BuildValue("k", (unsigned
long)element). The 'I' change is cleaner. Note their valgrind/CI run on x86-64 will not catch this because of the incidental
zero-extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's safe to use I (
unsigned int) as the format specifier since it's only guaranteed to be at least 2 bytes large. In theory ifunsigned intwas 2 bytes large, I think passing in an unsigned 32-bit integer value toIwould cause the value to be truncated or cause undefined behavior.unsigned longis always at least 32 bits long, so I think theunsigned longcast is not needed;unsigned longcan always accomodate auint32_tvalue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on the
Ipoint. I think the problem is whenkcauses Py_BuildValue to read 64 bits where element is only a 32 bit unsigned int that isn't promoted because Py_BuildValue uses variadic arguments. I thinkPy_BuildValue("k", (unsigned long)element);would make this safe. Let me know what you think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'll make that change