scitbx: fix flex.*_from_byte_str truncation of non-ASCII Unicode input#1169
Draft
bkpoon wants to merge 1 commit into
Draft
scitbx: fix flex.*_from_byte_str truncation of non-ASCII Unicode input#1169bkpoon wants to merge 1 commit into
bkpoon wants to merge 1 commit into
Conversation
bkpoon
commented
Jun 6, 2026
Member
- shared_from_byte_str (flex.int_from_byte_str, double_from_byte_str, size_t_from_byte_str, ...) re-encodes a unicode argument to UTF-8 bytes but took its length from len(byte_str), the code-point count; for non-ASCII input that is smaller than the UTF-8 buffer, so the resulting array was silently truncated
- take the length from the byte buffer actually used (PyBytes_GET_SIZE), keeping the pointer and size consistent
- own the re-encoded UTF-8 bytes with handle<>, releasing them; the unicode branch previously leaked the PyUnicode_AsUTF8String reference
- add exercise_from_byte_str_unicode regression test
- shared_from_byte_str (flex.int_from_byte_str, double_from_byte_str, size_t_from_byte_str, ...) re-encodes a unicode argument to UTF-8 bytes but took its length from len(byte_str), the code-point count; for non-ASCII input that is smaller than the UTF-8 buffer, so the resulting array was silently truncated - take the length from the byte buffer actually used (PyBytes_GET_SIZE), keeping the pointer and size consistent - own the re-encoded UTF-8 bytes with handle<>, releasing them; the unicode branch previously leaked the PyUnicode_AsUTF8String reference - add exercise_from_byte_str_unicode regression test
Member
Author
|
LIke 5c7d953 but for byte strings. Do detector data use byte strings? |
phyy-nx
reviewed
Jun 8, 2026
phyy-nx
left a comment
Contributor
There was a problem hiding this comment.
Ran the dials and dxtbx tests on this branch, no problems. Did a search in both for "from_byte_str", didn't find it.
Found two references to it in iotbx.detector, in a function called 'slice_callback_with_high_performance_http_data' which I believe was used by the original spotfinder server (dials has a new one). Both follow this kind of pattern:
BYU = self.object.read()
linearintdata = flex.int_from_byte_str(BYU)
provisional_size = linearintdata.size()
assert provisional_size == self.size1*self.size2
Which to me looks like a self-consistency check that would have alerted the user to a problem here already. So to me, this change set seems reasonable.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.