fix: validate library and data paths at the application boundary

This commit is contained in:
阿白叔 committed 2026-11-23 18:06:17 +08:00
1 parent 47c2cfecc6
commit 6d2b6de027
10 files changed
+336 -36

No files matched your search

+2 -10
View File
@@ -4,7 +4,7 @@ import logging
import json
from collections import Counter, defaultdict
from .models import CbbRecord, LibraryReadResult
from .network_path import absolute_preserving_drive
from .network_path import absolute_preserving_drive, validate_library_file
logger = logging.getLogger(__name__)
CACHE_SCHEMA_VERSION = 2
@@ -206,15 +206,7 @@ def read_library_fast(path: Path, *, status_reader=None):
"""Discover directories; this does not validate native format/registration."""
try:
path = Path(path)
if path.suffix.casefold() != '.lmc':
return LibraryReadResult((), 'INPUT_SUFFIX: 请选择 .lmc 中心库文件。')
if not path.is_file():
return LibraryReadResult((), f'INPUT_MISSING: 中心库不存在或不是文件: {path}')
with path.open('rb') as stream:
if not stream.read(1):
return LibraryReadResult((), 'INPUT_EMPTY: 中心库文件为空。')
if any(lock.is_dir() for lock in (path.with_suffix('.lock'), path.with_name('.'+path.stem+'.cbb-upload.lock'))):
return LibraryReadResult((), 'INPUT_LOCK_DIRECTORY: 中心库锁路径是目录。')
validate_library_file(path)
folder = path.parent/'ReusableBlocksLP'
if folder.exists() and not folder.is_dir():
return LibraryReadResult((), f'INPUT_DIRECTORY: ReusableBlocksLP 不是目录: {folder}')