microsoft / microsoft/kiota-python

JSON deserialization does not handle OverflowError

Open
#480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
31
Forks
39
Avg merge
11h 45m
Merged PRs (30d)
42

Description

Trying to deserialize certain misformatted strings result in an uncaught OverflowError exception instead of passing through the string unchanged. In particular, trying to deserialize a timedelta string such as "50001140846:00021" results in the following:

Traceback (most recent call last):
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 66, in parse_timedelta_string
    return parse_timedelta_from_iso_format(text)
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 34, in parse_timedelta_from_iso_format
    raise ValueError(f"Invalid ISO8601 duration string: {text}")
ValueError: Invalid ISO8601 duration string: 50001140846:00021

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[...]
  File "lib\site-packages\kiota_serialization_json\json_parse_node.py", line 335, in try_get_anything
    return parse_timedelta_string(value)
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 76, in parse_timedelta_string
    return timedelta(hours=hours, minutes=minutes, seconds=seconds)
OverflowError: days=2083380868; must have magnitude <= 999999999

The issue is that JsonParseNode.try_get_anything() only handles ValueError exceptions instead of also handling OverflowError. Changing this line to catch both ValueError and OverflowError allows deserialization to be successful:
https://github.com/microsoft/kiota-python/blob/b23edcbf268efdb81d14ef59cecc6c9565288248/packages/serialization/json/kiota_serialization_json/json_parse_node.py#L336

Most likely the other catch handlers in try_get_anything() should be updated as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/serialization/json/kiota_serialization_json/json_parse_node.py, at JsonParseNode.try_get_anything() and the catch around parse_timedelta_string(). Reproduce the input "50001140846:00021" and check the other catch handlers mentioned in the issue. Done means malformed values pass through unchanged without an uncaught OverflowError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.