Non-UTF-8 extension catalog aborts the whole merge
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #5196 của @chelsealong — đã merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
Hướng nghiên cứu
Đọc src/specify_cli/extensions/__init__.py quanh _fetch_single_catalog và _get_merged_extensions, sau đó theo dõi cách xử lý lỗi tìm nạp và lỗi phân tích cú pháp JSON. Tái hiện quá trình hợp nhất với một catalog có UTF-8 không hợp lệ và một catalog bình thường, dùng trường hợp JSON không hợp lệ để so sánh. Hoàn tất khi nguồn bị lỗi được bỏ qua kèm cảnh báo và catalog bình thường vẫn đóng góp kết quả; nếu tất cả nguồn đều lỗi thì vẫn phải phát sinh ngoại lệ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- Repository:
github/spec-kit - Target commit:
1c799bda6c136fcf42fb3475a922ccaac57e6c71 - File:
src/specify_cli/extensions/__init__.py:4700-4725
Summary
non-UTF-8 extension catalog aborts the whole merge.
Root cause
ExtensionCatalog._fetch_single_catalog catches URLError and JSONDecodeError, but the UTF-8 decode raises UnicodeDecodeError, which escapes.
Affected code
src/specify_cli/extensions/__init__.py:
4690
4691 Returns:
4692 URL of the primary catalog
4693
4694 Raises:
4695 ValidationError: If a catalog URL is invalid
4696 """
4697 active = self.get_active_catalogs()
4698 return active[0].url if active else self.DEFAULT_CATALOG_URL
4699
4700 def _fetch_single_catalog(
4701 self, entry: CatalogEntry, force_refresh: bool = False
4702 ) -> Dict[str, Any]:
4703 """Fetch a single catalog with per-URL caching.
4704
4705 For the DEFAULT_CATALOG_URL, uses legacy cache files (self.cache_file /
4706 self.cache_metadata_file) for backward compatibility. For all other URLs,
4707 uses URL-hash-based cache files in self.cache_dir.
4708
4709 Args:
4710 entry: CatalogEntry describing the catalog to fetch
4711 force_refresh: If True, bypass cache
4712
4713 Returns:
4714 Catalog data dictionary
4715
4716 Raises:
4717 ExtensionError: If catalog cannot be fetched or has invalid format
4718 """
4719 import urllib.error
4720
4721 # Determine cache file paths (backward compat for default catalog)
4722 if entry.url == self.DEFAULT_CATALOG_URL:
4723 cache_file = self.cache_file
4724 cache_meta_file = self.cache_metadata_file
4725 is_valid = not force_refresh and self.is_cache_valid()
4726 else:
4727 url_hash = hashlib.sha256(entry.url.encode()).hexdigest()[:16]
4728 cache_file = self.cache_dir / f"catalog-{url_hash}.json"
4729 cache_meta_file = self.cache_dir / f"catalog-{url_hash}-metadata.json"
4730 is_valid = False
4731 if not force_refresh and cache_file.exists() and cache_meta_file.exists():
4732 try:
4733 metadata = json.loads(cache_meta_file.read_text(encoding="utf-8"))
4734 cached_at = datetime.fromisoformat(metadata.get("cached_at", ""))
4735 if cached_at.tzinfo is None:
4736 cached_at = cached_at.replace(tzinfo=timezone.utc)
4737 age = (datetime.now(timezone.utc) - cached_at).total_seconds()
4738 is_valid = age < self.CACHE_DURATION
4739 except (
4740 json.JSONDecodeError,
4741 OSError,
4742 UnicodeError,
4743 ValueError,
4744 KeyError,
4745 TypeError,
4746 AttributeError,
4747 ):
4748 # Cache validity is best-effort: invalid/missing metadata
4749 # fields, an unreadable metadata file (permissions / disk),
4750 # a wrongly-encoded metadata file (written by a tool using
Expected behavior
Extension catalogs warn and skip a failed source and raise only when every selected source fails.
Actual behavior
ExtensionCatalog._fetch_single_catalog parses untrusted response bytes with json.loads but catches only urllib.errors.URLError and json.JSONDecodeError; an invalid-UTF-8 response raises UnicodeDecodeError, and _get_merged_extensions catches only ExtensionError, so a non-UTF-8 source aborts the whole extension catalog operation instead of warning and continuing.
Steps to reproduce
- Run the real
ExtensionCatalogmerge with one catalog whose body is invalid UTF-8 and one healthy catalog. - Observe the returned list and the exception path.
- Compare with an invalid-JSON catalog as a control.
Suggested fix
Translate UnicodeDecodeError into the catalog error type, or catch it alongside JSONDecodeError.
Impact
One corrupt remote catalog disables all extension operations that depend on the merged catalog, including unrelated healthy catalogs.
- Ngôn ngữ chính
- Python
- Star
- 144k
- Fork
- 12.9k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 181
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github/spec-kit
-
bundle catalog add rewrites Windows drive paths as POSIX pathsCó thể đã có người làm @chelsealong đã nhận 2 ngày trước. Đang mởtriage-must-have
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The Python branch-creation port accepts an oversized `--number` and crashes at `int()` instead of rejecting itCó thể đã có người làm @github-actions đã nhận 3 ngày trước. Đang mởbug-assess bug-fix fix-proposed severity-low triage-can-wait
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
github/spec-kit#5194 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Cline extension and preset commands have `speckit.*.md` file names rewritten to `speckit-*-md`Có thể đã có người làm @kevin9327 đã nhận 5 ngày trước. Đang mởtriage-can-wait
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: `create-new-feature.sh` rejects the feature descriptions `-n`, `-e` and `-E`, which the Python script acceptsCó thể đã có người làm @WOLIKIMCHENG đã nhận 7 ngày trước. Đang mởtriage-can-wait
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: `bundle init <bundle>` initialises with the default integration instead of the bundle's, then aborts with a clashCó thể đã có người làm @chelsealong đã nhận 9 ngày trước. Đang mởtriage-must-have
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của github/spec-kit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
elviskahoro/sdk-python-attio#144 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
RenyiELBO raises TypeError when model has no sample sitesCó thể đã có người làm @alibb007 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Four evaluation scripts unpack init_memmachine_params's five return values into three namesĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
MemMachine/MemMachine#1911 ·
Maintainer thường phản hồi trong vòng 3 ngày