Skip to content

Commit 10ef4e6

Browse files
committed
add size checks for invocations
1 parent 2158f32 commit 10ef4e6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/onepassword/core.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
from onepassword.errors import raise_typed_exception
55

6+
# In empirical tests, we determined that maximum message size that can cross the FFI boundary
7+
# is ~128MB. Past this limit, FFI will throw an error and the program will crash.
8+
# We set the limit to 50MB to be safe and consistent with the other SDKs, to be reconsidered upon further testing
9+
MESSAGE_LIMIT = 50 * 1024 * 1024;
610

711
machine_arch = platform.machine().lower()
812

@@ -26,16 +30,24 @@ async def _init_client(client_config):
2630

2731
# Invoke calls specified business logic from the SDK core.
2832
async def _invoke(invoke_config):
33+
serialized_config = json.dumps(invoke_config)
34+
if len(serialized_config) > MESSAGE_LIMIT:
35+
raise ValueError(
36+
f"Message size exceeds the limit of {MESSAGE_LIMIT} bytes.")
2937
try:
30-
return await core.invoke(json.dumps(invoke_config))
38+
return await core.invoke(serialized_config)
3139
except Exception as e:
3240
raise_typed_exception(e)
3341

3442

3543
# Invoke calls specified business logic from the SDK core.
3644
def _invoke_sync(invoke_config):
45+
serialized_config = json.dumps(invoke_config)
46+
if len(serialized_config) > MESSAGE_LIMIT:
47+
raise ValueError(
48+
f"Message size exceeds the limit of {MESSAGE_LIMIT} bytes.")
3749
try:
38-
return core.invoke_sync(json.dumps(invoke_config))
50+
return core.invoke_sync(serialized_config)
3951
except Exception as e:
4052
raise_typed_exception(e)
4153

0 commit comments

Comments
 (0)