Repository navigation
Serialize ints below the 4-byte range through the long path - #443
Open
abhishekcpp007 wants to merge 1 commit into
Open
abhishekcpp007 wants to merge 1 commit into
abhishekcpp007 wants to merge 1 commit into
Conversation
_save_integral only checked the upper bound, so anything below -2**31 reached struct.pack('!i') and raised a bare struct.error while the same magnitude positive value took the LONGINT path. Check both bounds, and have _write_int4 raise DumpError for either side.
This branch has not been deployed
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.
_save_integralonly checked the upper bound, so any int below-2**31went down the 4-byteINT/LONGopcode path andstruct.pack("!i", i)raised a barestruct.error. Positive values above2**31 - 1were already routed throughLONGINT/LONGLONG, so2**40round-tripped and-2**40did not.Over a gateway the same thing shows up as a
RemoteErrorending in_write_int4 ... struct.errorfromchannel.send(-2**40), whilechannel.send(2**40)arrives fine. A negative nanosecond timestamp or a hash value gets there easily.The fix adds
FOUR_BYTE_INT_MINand checks both bounds in_save_integral, so anything outside the 4-byte range takes the string-backed long path._write_int4now rejects values below the minimum withDumpError, the library's own exception, instead of leakingstruct.error. The wire format is unchanged:load_longintalready doesint(s)and handles the sign, so an old receiver reads the new output.Tests:
2**31,-(2**31) - 1,10**30and-(10**30)join theTestSerializeAPImatrix intesting/test_basics.py(dumps/loads, mmap and BytesIO), andtest_negative_longintesting/test_serializer.pymirrorstest_longfor the cross-interpreter path.Verified in a
python:3.12container (pip install pytest -e ., gevent/eventlet deselected):479 passed, 125 skipped, 6 xfailed, 11 xpassed, plus the 5test_remote_exec_module_is_removedvariants that also fail on unmodifiedmainwhen run together (they depend on a cached remote module, which testing: Drop cached remote module in test_remote_exec_module_is_removed #442 addresses)src:7 failed(struct.erroron every negative case)