Skip to content

Honor MAX_TEXT_BYTES before binary detection to avoid hashing huge files - #15

Merged
svenbuild merged 1 commit into
mainfrom
codex/fix-binary-handling-to-prevent-dos-risk
Mar 31, 2026
Merged

svenbuild merged 1 commit into
mainfrom
codex/fix-binary-handling-to-prevent-dos-risk

Conversation

@svenbuild

Copy link
Copy Markdown
Owner

Motivation

  • A previous change classified files as Binary based on a small sample before checking file size, which allows very large binaries to be fully hashed and can stall the UI or exhaust I/O.
  • Directory status logic also allowed Binary/Image to win over TooLarge, masking oversized files from the text-size guard.

Description

  • Reordered detect_file_kind_from_metadata_sample so it returns DetectedFileKind::TooLarge when metadata.len() > MAX_TEXT_BYTES before any binary/image sampling.
  • Reordered classify_entry_status_from_kinds so TooLarge is prioritized over Binary/Image when determining directory entry status.
  • Added two regression tests: detect_file_kind_marks_large_binary_as_too_large and classify_entry_status_prioritizes_too_large_over_binary to lock in the behavior.

Testing

  • Ran cargo fmt --check, which passed after formatting changes.
  • Attempted cargo test --lib detect_file_kind_marks_large_binary_as_too_large, but the build failed in this environment due to a missing system dependency (glib-2.0 / pkg-config), so the test could not be executed here.
  • Because the native glib-2.0 dependency is required by glib-sys, the full test suite could not be run in this container (build-time system library missing).

Codex Task

@svenbuild
svenbuild merged commit dee408c into main Mar 31, 2026
1 check failed
@svenbuild
svenbuild deleted the codex/fix-binary-handling-to-prevent-dos-risk branch March 31, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant