Skip to content

Commit

Permalink
client: allow file upload size to be sent a string
Browse files Browse the repository at this point in the history
... for uploads which sizes exceed the xmlrpc.client.MAXINT limit for int
values.  This change should not be backwards incompatible.  Old client
with newer hub should work seamlessly.  And new hub with older client
would crash with the following traceback anyway.

Fixes the following traceback:
```
$ truncate -s 2G test
$ osh/client/osh-cli mock-build --tarball-build-script=test ./test
Traceback (most recent call last):
  File "/src/osh/client/osh-cli", line 79, in <module>
    main()
  File "/src/osh/client/osh-cli", line 72, in main
    parser.run()
  File "/src/kobo/kobo/cli.py", line 296, in run
    cmd.run(*cmd_args, **cmd_kwargs)
  File "/src/osh/client/commands/cmd_diff_build.py", line 157, in run
    target_dir, self.parser)
  File "/src/osh/client/commands/shortcuts.py", line 145, in upload_file
    return hub.upload_file(os.path.expanduser(srpm), target_dir)
  File "/src/kobo/kobo/client/__init__.py", line 473, in upload_file
    upload_id, upload_key = self.upload.register_upload(os.path.basename(file_name), checksum, fsize, target_dir)
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 1446, in __request
    allow_none=self.__allow_none).encode(self.__encoding, 'xmlcharrefreplace')
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 971, in dumps
    data = m.dumps(params)
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 502, in dumps
    dump(v, write)
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 524, in __dump
    f(self, value, write)
  File "/usr/lib64/python3.6/xmlrpc/client.py", line 540, in dump_long
    raise OverflowError("int exceeds XML-RPC limits")
OverflowError: int exceeds XML-RPC limits
```

Resolves: #216
  • Loading branch information
lzaoral committed Aug 22, 2023
1 parent c62ddee commit 9454b52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions kobo/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ def upload_file(self, file_name, target_dir):
checksum = sum.hexdigest().lower()

fsize = os.path.getsize(file_name)
# use str only for large uploads to not break compatibility with older hubs
if fsize > xmlrpclib.MAXINT:
fsize = str(fsize)

upload_id, upload_key = self.upload.register_upload(os.path.basename(file_name), checksum, fsize, target_dir)

secure = (scheme == "https")
Expand Down
3 changes: 2 additions & 1 deletion kobo/django/upload/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def register_upload(request, name, checksum, size, target_dir):
upload.owner = request.user
upload.name = name
upload.checksum = checksum.lower()
upload.size = size
# size may be sent as a string to workaround the xmlrpc.client.MAXINT limit
upload.size = int(size)
upload.target_dir = target_dir
upload.save()
return (upload.id, upload.upload_key)
Expand Down

0 comments on commit 9454b52

Please sign in to comment.