Skip to content

fix: handle empty files in last_n_bytes_of#4687

Open
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/empty-file-last-n-bytes
Open

fix: handle empty files in last_n_bytes_of#4687
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/empty-file-last-n-bytes

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

Bug

glint checks the final newline through envoy.base.utils.last_n_bytes_of().
On a 0-byte file that helper does a negative seek and blows up with OSError: [Errno 22] Invalid argument, so the check crashes instead of flagging the file. Empty files are normal repo inputs, so this edge case is pretty legit.

Fix

Clamp the seek offset to 0. Empty and short files now return the available tail bytes, nice and boring.

Repro

Before this change:

python - <<'PY'
from pathlib import Path
from tempfile import TemporaryDirectory
from envoy.code.check.abstract.glint import NewlineChecker

with TemporaryDirectory() as tmp:
    root = Path(tmp)
    empty = root / "empty.txt"
    empty.write_bytes(b"")
    print(NewlineChecker(root).no_newlines([empty.name]))
PY

This raised OSError: [Errno 22] Invalid argument.

After this change the same snippet returns {'empty.txt'}.

Checks

pytest -q py/envoy.base.utils/tests/test_utils.py -k 'last_n_bytes_of or ellipsize or is_sha'
pytest -q py/envoy.code.check/tests/test_abstract_glint.py -k 'newline_checker_no_newlines or glint_no_newlines or files_with_no_newline'

@netlify

netlify Bot commented Jun 22, 2026

Copy link
Copy Markdown

Deploy Preview for nifty-bassi-e26446 ready!

Name Link
🔨 Latest commit ee7011d
🔍 Latest deploy log https://app.netlify.com/projects/nifty-bassi-e26446/deploys/6a3973cac4d7670008dbcb0b
😎 Deploy Preview https://deploy-preview-4687--nifty-bassi-e26446.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell immanuwell force-pushed the fix/empty-file-last-n-bytes branch from ca22b6b to ee7011d Compare June 22, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant