Skip to content

Commit 70c2620

Browse files
committed
19774 FIX Handle corrupted data files gracefully instead of crashing
Crash-Group-ID: 3380 Jira: CMK-33559 Change-Id: I29da9ff5b73abd64b0e70fc3e5cf6744267449e6
1 parent 8dfe26e commit 70c2620

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

.werks/19774.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[//]: # (werk v3)
2+
# Handle corrupted data files gracefully instead of crashing
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-04-14T13:00:00+00:00
7+
version | 2.5.0b5
8+
class | fix
9+
edition | community
10+
component | core
11+
level | 1
12+
compatible | yes
13+
14+
When a Checkmk data file (`.mk` file) became corrupted (e.g., filled with null
15+
bytes due to a filesystem issue), loading it would crash with a `SyntaxError:
16+
source code string cannot contain null bytes`. This was most commonly observed
17+
on the notification analysis page when the notification backlog file was
18+
corrupted.
19+
20+
Checkmk now gracefully falls back to the default value when a data file cannot
21+
be deserialized, and logs a warning.

packages/cmk-ccc/cmk/ccc/store/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def load_object_from_file(path: Path, *, default: Any, lock: bool = False) -> An
192192
tracer.simple_span("load_object_from_file", path),
193193
_leave_locked_unless_exception(path) if lock else nullcontext(),
194194
):
195-
return ObjectStore(path, serializer=DimSerializer()).read_obj(default=default)
195+
try:
196+
return ObjectStore(path, serializer=DimSerializer()).read_obj(default=default)
197+
except (SyntaxError, ValueError):
198+
logger.warning("Failed to deserialize %s, returning default", path)
199+
return default
196200

197201

198202
def load_object_from_pickle_file(path: Path, *, default: Any, lock: bool = False) -> Any:

packages/cmk-ccc/tests/test_store.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ def test_save_text_to_file(tmp_path: Path, data: str) -> None:
212212
assert store.load_text_from_file(path) == data
213213

214214

215-
@pytest.mark.xfail(strict=True, reason="Crash group 3380: SyntaxError on null bytes in file")
216215
def test_load_object_from_file_null_bytes(tmp_path: Path) -> None:
217216
"""A file containing null bytes should return default, not crash with SyntaxError."""
218217
path = tmp_path / "corrupted.mk"

0 commit comments

Comments
 (0)