Malformed repository JSON / invalid release version raises uncaught exceptions and aborts the whole package listing
A single malformed third-party repository (wrong JSON type, or an invalid version string) raises an uncaught exception that aborts the whole available-packages listing.
Found by feeding JsonRepositoryProvider (the real class shipped in Package Control 4.2.8, running inside Sublime Text 4) about 140 mutations of a valid repository JSON served from a local HTTP server. Most bad input is handled (InvalidPackageReleaseKeyError / broken_packages), but these raise non-provider exceptions out of get_packages():
| repository content | exception |
|---|---|
root JSON is [], null, "str" or 5 |
TypeError: list indices must be integers... / 'NoneType' object is not subscriptable |
"packages": [null] or [1, "x"] |
AttributeError: 'NoneType'/'int' object has no attribute 'get' |
"releases": [null], [1], [[]] |
AttributeError: ... has no attribute 'get' |
package "name": ["a"] |
TypeError: unhashable type: 'list' |
package "readme": 5 or "details": 5 |
AttributeError: 'int' object has no attribute 'startswith' |
release "url": 5 |
AttributeError: 'int' object has no attribute 'startswith' |
"includes": ["x", 5] |
AttributeError: 'int' object has no attribute 'startswith' |
100000 nested [ |
RecursionError while decoding |
And a second stage: the provider accepts "version": "abc" (also "1.0.0-", "v") and yields the package, but PackageManager.select_releases() then raises PEP440InvalidVersionError on it:
pm.select_releases('Good Pkg', [{'version': 'abc', 'url': 'https://example.com/g.zip', 'date': '2020-01-01 00:00:00', 'sublime_text': '>=3000', 'platforms': ['*']}])
# PEP440InvalidVersionError: 'abc' is not a valid PEP440 version string
Why it matters: in 4.2.8, PackageManager.list_available_packages() does for name, info in provider.get_packages(): info['releases'] = self.select_releases(...) (and the same for libraries) with no try/except, so one bad third-party repository (or one bad release in it) makes Install Package / Upgrade Package fail for every package, not just that repository's. On master (1c52ef1) base_provider.fetch() catches DownloaderException only and except BaseException as exc: ...; raise re-raises everything else, so the same inputs still propagate out of the fetch.
Suggested fix: validate types in JsonRepositoryProvider (raise InvalidRepoFileException/InvalidPackageReleaseKeyError so the package/repo goes to broken_packages/failed_sources), validate version with PackageVersion(...) there, and wrap the per-repository processing loop in list_available_packages so one repository can't take down the rest. Happy to share the fixture generator.
Same exercise against ChannelProvider (schema 4.0.0 channel with repositories, packages_cache, libraries_cache; 86 mutations of a fixture that parses cleanly): 37 raise non-provider exceptions out of get_repositories() / get_packages(repo) / get_libraries(repo), 45 are silently accepted, 4 give a ProviderException. Leaks:
repositories:null,5->TypeError: ... is not iterable;[1]->AttributeError: 'int' object has no attribute 'startswith'packages_cache/libraries_cache=null,5,"str",[],[null],[1]->AttributeError: '...' object has no attribute 'values';{"x": 1}->TypeErrorpackages_cache[<repo>]/libraries_cache[<repo>]=null,5,"x",[null],[5],["x"]->TypeError- a cached package or library with
"releases": null|[null]|[1], or a release with"version": null|5->TypeError: None is not a string/'NoneType' object is not iterable
And nothing at all is validated for the entries themselves: package name values of null, 5, ["a"], "", .., ., ../evil, a/b, C:\x, User and a library named ../x are all returned as valid packages/libraries (see also #1768), as are url: null|5|http://..., date: 5, sublime_text: 5|"garbage", platforms: 5|null|"*".
I understand the official channel is machine-generated by the crawler and can be trusted more than an arbitrary repository, but custom channels are a supported setting, and the channel loop in list_available_packages only catches (DownloaderException, ClientException, ProviderException), so any of the above aborts the whole listing here too.