dhkim1920 commented on code in PR #73783:
URL: https://github.com/apache/airflow/pull/73783#discussion_r4538237880
##########
task-sdk/src/airflow/sdk/execution_time/comms.py:
##########
@@ -177,14 +181,42 @@ def _new_encoder() -> msgspec.msgpack.Encoder:
return msgspec.msgpack.Encoder(enc_hook=_msgpack_enc_hook)
+def _encode_large_ints(value: Any) -> Any:
+ if isinstance(value, int) and not -(2**63) <= value < 2**64:
+ return msgspec.msgpack.Ext(
+ MSGPACK_HUGEINT, value.to_bytes((value.bit_length() + 8) // 8,
"big", signed=True)
+ )
+ if isinstance(value, dict):
+ return {key: _encode_large_ints(item) for key, item in value.items()}
+ if isinstance(value, (list, tuple)):
+ return [_encode_large_ints(item) for item in value]
+ return value
+
+
+def _decode_msgpack_ext(code: int, data: memoryview) -> Any:
+ if code == MSGPACK_HUGEINT:
+ return int.from_bytes(data, "big", signed=True)
+ return msgspec.msgpack.Ext(code, data)
Review Comment:
Thanks for catching this. I reproduced the issue: an unknown extension could
retain a view into the receive buffer, so reusing that buffer could change an
already decoded value. I updated this to use bytes(data) and added a regression
test that verifies the decoded value remains unchanged after modifying the
receive buffer
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]