Skip to content

Commit 0467576

Browse files
committed
Accept padded audit log row counts
1 parent e254579 commit 0467576

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/kernel/lib/audit_log_download.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,12 @@ def _parse_chunk_headers(headers: httpx.Headers, current_cursor: str | None) ->
201201
has_more = has_more_value == "true"
202202

203203
row_count = headers.get("x-row-count")
204-
if (
205-
row_count is None
206-
or not row_count.isascii()
207-
or not row_count.isdecimal()
208-
or len(row_count) > len(str(_MAX_CHUNK_ROWS))
209-
):
204+
if row_count is None or not row_count.isascii() or not row_count.isdecimal():
210205
raise AuditLogDownloadError("response missing or invalid X-Row-Count header")
211-
rows = int(row_count)
206+
normalized_row_count = row_count.lstrip("0") or "0"
207+
if len(normalized_row_count) > len(str(_MAX_CHUNK_ROWS)):
208+
raise AuditLogDownloadError("response missing or invalid X-Row-Count header")
209+
rows = int(normalized_row_count)
212210
if rows > _MAX_CHUNK_ROWS:
213211
raise AuditLogDownloadError("response missing or invalid X-Row-Count header")
214212

tests/test_audit_log_download.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ def test_download_rejects_invalid_row_count(row_count: str, client: Kernel, resp
221221
assert destination.getvalue() == b""
222222

223223

224+
def test_download_accepts_zero_padded_row_count(client: Kernel, respx_mock: MockRouter) -> None:
225+
response = chunk_response(b"chunk", rows=1, has_more=False)
226+
response.headers["x-row-count"] = "0" * 5000 + "1"
227+
respx_mock.get("/audit-logs/export/chunk").mock(return_value=response)
228+
229+
result = client.audit_logs.download(
230+
to=BytesIO(),
231+
start="2026-06-01T00:00:00Z",
232+
end="2026-06-02T00:00:00Z",
233+
)
234+
235+
assert result.rows == 1
236+
237+
224238
class InvalidWriteDestination:
225239
def __init__(self, result: object) -> None:
226240
self.result = result

0 commit comments

Comments
 (0)