Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This document records all notable changes to [HTTPie](https://httpie.io).
This project adheres to [Semantic Versioning](https://semver.org/).

## [unreleased](https://github.com/httpie/cli/compare/3.2.4...master)

- Fixed an unhandled `OverflowError`/`MemoryError` crash when an out-of-range array index was used in the nested JSON syntax (e.g. `item[99999999999999999999999]:=1`); a clear error is now reported instead.

## [3.2.4](https://github.com/httpie/cli/compare/3.2.3...3.2.4) (2024-11-01)

- Fix default certs loading and unpin `requests`. ([#1596](https://github.com/httpie/cli/issues/1596))
Expand Down
10 changes: 9 additions & 1 deletion httpie/cli/nested_json/interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ def object_for(kind: PathAction) -> Any:
message='Negative indexes are not supported.',
message_kind='Value',
)
cursor.extend([None] * (path.accessor - len(cursor) + 1))
try:
cursor.extend([None] * (path.accessor - len(cursor) + 1))
except (OverflowError, MemoryError):
raise NestedJSONSyntaxError(
source=key,
token=path.tokens[1],
message='The index is too large.',
message_kind='Value',
) from None
Comment on lines +87 to +95
if next_path.kind is PathAction.SET:
cursor[path.accessor] = next_path.accessor
break
Expand Down
12 changes: 12 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,18 @@ def test_nested_json_syntax(input_json, expected_json, httpbin):
['foo[-10]:=[1,2]'],
'HTTPie Value Error: Negative indexes are not supported.\nfoo[-10]\n ^^^',
),
(
['foo[99999999999999999999999]:=1'],
'HTTPie Value Error: The index is too large.'
'\nfoo[99999999999999999999999]'
'\n ^^^^^^^^^^^^^^^^^^^^^^^',
),
(
['foo[1000000000000000000]:=1'],
'HTTPie Value Error: The index is too large.'
'\nfoo[1000000000000000000]'
'\n ^^^^^^^^^^^^^^^^^^^',
),
(
['foo[0]:=1', 'foo[]:=2', 'foo[\\2]:=3'],
"HTTPie Type Error: Cannot perform 'key' based access on 'foo' which has a type of 'array' but this operation requires a type of 'object'.\nfoo[\\2]\n ^^^^",
Expand Down
Loading