Skip to content

fix(std): refuse non-regular files, full JPEG SOF range, list truncation marker - #96

Merged
M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
M3gA-Mind:fix/std-low-hardening
Oct 23, 2026
Merged

M3gA-Mind merged 2 commits into
tinyhumansai:mainfrom
M3gA-Mind:fix/std-low-hardening

Conversation

@M3gA-Mind

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes four small robustness gaps in the tinytools-std filesystem tools.

  • file_read and edit_file blocked on a FIFO. Both tools check metadata (size) and then call read_to_string. A FIFO has length 0, so it passes the size check, and then the read blocks forever while waiting for a writer. A character device can stream without end in the same way. Both tools now refuse anything that is not a regular file (<path> is not a regular file) before reading.
  • image_info missed most JPEG SOF markers. It read dimensions only from SOF0 to SOF3 (0xC0..=0xC3). Every SOF marker from 0xC0 to 0xCF carries the frame size, except C4 (DHT), C8 (JPG) and CC (DAC). Arithmetic-coded and lossless JPEGs (SOF5 to SOF15) therefore came back without dimensions. The scan now covers the whole range and skips those three markers as ordinary segments.
  • image_info returned I/O failures as Err. A metadata or read failure became an anyhow error, unlike every other filesystem tool. Both now return a ToolResult error with the same message, so the model sees the reason.
  • list_files truncated without saying so. It stops at MAX_ENTRIES (1000), and the output looked like a complete listing. When at least one more entry exists, it now ends with ... listing stopped at 1000 entries [truncated].

Related issue

None.

API or behavior changes

  • file_read / edit_file on a FIFO, socket, device or directory now return <path> is not a regular file. Before, a FIFO blocked, and a directory produced the OS read error.
  • image_info now reports dimensions for SOF5 to SOF15 JPEGs. A metadata or read failure is now Ok(ToolResult::error(..)) and no longer Err. A missing path argument is unchanged.
  • list_files adds a truncation line when it hits the entry cap. When it does not, the output is unchanged.

Validation

Commands actually run, with their outcome:

  • cargo fmt --all -- --check: rustfmt --edition 2024 on the touched files only.

  • N/A: cargo clippy --all-targets --all-features -- -D warnings was left to CI.

  • N/A: cargo build --all-targets --all-features was left to CI.

  • N/A: cargo test --all-features was left to CI. Only the tests below ran locally. Before the fix, all 5 failed:

    • a_fifo_is_refused_not_read: file_read blocked on a FIFO: Elapsed(()) (5 s timeout);
    • edit_refuses_a_fifo: edit blocked on a FIFO: Elapsed(());
    • jpeg_dimensions_come_from_every_sof_marker_and_skip_c4_c8_cc: SOF 0xC5 gave None;
    • execute_on_a_directory_reports_a_read_failure (updated): the call returned Err;
    • a_capped_listing_says_it_was_truncated: no marker.

    After the fix, these and the rest of the image_info tests plus listing_stops_at_the_entry_cap passed (30 tests).

Tests

  • file_read/extra_tests.rs::a_fifo_is_refused_not_read and edit_file/mod_tests.rs::edit_refuses_a_fifo (unix only) create a FIFO with mkfifo and expect a refusal within 5 s. Afterwards they open the FIFO for writing on a detached thread, so a failing run still shuts down.
  • image_info/mod_tests.rs::jpeg_dimensions_come_from_every_sof_marker_and_skip_c4_c8_cc reads dimensions from all 13 SOF markers and skips C4, C8 and CC.
  • image_info/mod_tests.rs::execute_on_a_directory_reports_a_read_failure used to assert the old Err and now expects a ToolResult error.
  • list_files/extra_tests.rs::a_capped_listing_says_it_was_truncated: 1001 entries produce the marker, and 1000 entries do not.

Not in this PR: giving image_info an execute_with_context and a rate limit. Both are host-policy questions, not robustness fixes.

Documentation

Not needed.

Checklist

  • The change is focused on one logical change
  • No new #[allow(...)], #[ignore], or relaxed lints
  • No secrets, tokens, or .env contents in the diff or the description

@tinysweeper

tinysweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Reviewed head: 95e531b5b64b3be612d27b3f81f9440b4c6d2ac1

Verdict: Ready for maintainer review · Priority: none
Coverage: Reviewed 8 of 8 files.
Pull request purpose (title): fix(std): refuse non…

Diagnostics and supporting details

Full summary

Pull request purpose (title): fix(std): refuse non-regular files, full JPEG SOF range, list truncation marker. Tiny Sweeper completed its review; deterministic results follow.

Review snapshot

Change surface Files Review signal Count
Production 4 Active findings 0
Tests 4 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 0

Completeness: Complete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

What changed

file_read and edit_file check metadata after canonicalization and return `<path> is not a regular file` for any non-regular file before reading. image_info's dimension scan covers 0xC0..=0xCF excluding 0xC4, 0xC8 and 0xCC, and its metadata/read failures return Ok(ToolResult::error(..)). list_files sets a truncated flag when an entry exists past MAX_ENTRIES and appends `... listing stopped at 1000 entries [truncated]`. Tests were added or updated for each behavior, including a revised truncation test that creates MAX_ENTRIES+1 files then removes one.

Features

  • Modified — file_read refuses non-regular files: A FIFO, device or directory now yields `<path> is not a regular file` instead of blocking forever on the read or surfacing an OS read error. (crates/tinytools-std/src/filesystem/file_read/mod.rs impl FileReadTool {)
  • Modified — edit_file refuses non-regular files: edit_file performs the same regular-file check after metadata retrieval and before the read-modify-write section, so a FIFO or device cannot block the edit path. (crates/tinytools-std/src/filesystem/edit_file/mod.rs impl EditFileTool {)
  • Modified — image_info JPEG SOF range widened: Dimensions are extracted for SOF0–SOF15 markers (arithmetic-coded and lossless JPEGs), skipping DHT 0xC4, JPG 0xC8 and DAC 0xCC as ordinary segments. (crates/tinytools-std/src/filesystem/image_info/mod.rs impl ImageInfoTool {)
  • Modified — image_info I/O failures return ToolResult errors: Metadata and file-read failures now return Ok(ToolResult::error(..)) with the same messages, so the model sees the reason instead of a propagated anyhow Err, matching other filesystem tools. (crates/tinytools-std/src/filesystem/image_info/mod.rs impl Tool for ImageInfoTool {)
  • Modified — list_files truncation marker: When entries remain beyond MAX_ENTRIES, the output ends with an explicit truncation line; when the listing is complete, output is unchanged. (crates/tinytools-std/src/filesystem/list_files/mod.rs impl ListFilesTool {)

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Before merge

None.

How this fits together

flowchart LR
  n0["...fuses_a_replacement_that_outgrows_the_cap<br/>changed"]:::changed
  n1["a_paged_read_is_recorded_as_partial<br/>changed"]:::changed
  n2["...ute_on_a_directory_reports_a_read_failure<br/>changed"]:::changed
  n3["listing_stops_at_the_entry_cap<br/>changed"]:::changed
  n4["write"]:::impacted
  n5["with_file_state_agent_id"]:::impacted
  n6["...he_file_state_guard_and_records_its_write"]:::impacted
  n7["init_global"]:::impacted
  n0 -->|calls| n4
  n0 -->|tests| n4
  n1 -->|calls| n4
  n1 -->|tests| n4
  n1 -->|calls| n5
  n1 -->|tests| n5
  n1 -->|calls| n7
  n1 -->|tests| n7
  n3 -->|calls| n4
  n3 -->|tests| n4
  n6 -->|calls| n4
  n6 -->|tests| n4
  n6 -->|calls| n5
  n6 -->|tests| n5
  n6 -->|calls| n7
  n6 -->|tests| n7
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The new test is correct: the tool truncates once 1000 entries are collected, so a directory of 1001 files yields `[truncated]`, and after removing one file (1000 remain) the listing is untruncated and the marker is absent. No defect found. _The code index is behind this pull request (indexed at `28ea0933b938`), so retrieved context may be out of date._

security

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: This is a test-only addition that checks truncation reporting in `list_files`; I found no security-relevant change and no defect in the new test. The one thing I could not verify is whether `TempDir` is in scope in this file, but since the diff shows the existing test above it already uses `TempDir`, it is. _The code index is behind this pull request (indexed at `28ea0933b938`), so retrieved context may be out of date._

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The only change under review is a test for the new `list_files` truncation marker, and it is a real one: it asserts the marker appears at `MAX_ENTRIES + 1` entries and disappears when a file is removed, so a regression in either the `truncated` detection or the marker emission fails it. The listing truncation itself (noticed by consuming one extra `next_entry`) has a behavioural edge — that extra entry is dropped — but the marker text states the cap is a stop, not a page, so nothing is misrepresented. No testable behaviour in this diff is left uncovered. _The code index is behind this pull request (indexed at `28ea0933b938`), so retrieved context may be out of date._

commits

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Positive: No sensitive content detected in committed files.
  • Lane summary: No sensitive content in committed files. _The code index is behind this pull request (indexed at `28ea0933b938`), so retrieved context may be out of date._

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The new test `a_capped_listing_says_it_was_truncated` matches the truncation marker the implementation emits in `list_files/mod.rs`: it creates `MAX_ENTRIES + 1` entries (so one remains past the cap), asserts the output ends with `[truncated]`, then removes one and asserts the marker is gone. The PR description already covers this test and its behaviour, so nothing new is needed there. No defect in the added lines. _The code index is behind this pull request (indexed at `28ea0933b938`), so retrieved context may be out of date._
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.000445
  • Tokens: 152279 input · 3047 output · 22528 cached · 513 embedding
  • Updated: 2026-10-22T23:29:12Z
Head State Pass summary
79a4993fe30d ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-22T23:14:15Z)
95e531b5b64b ready for maintainer review 0 active finding(s), 0 resolved finding(s) (at 2026-10-22T23:29:12Z)

tinysweeper 0.1.2

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 579c7f60-b5ff-4e29-bbb7-7d2d52671d67
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tinysweeper found nothing blocking. Approving.

Diagnostics

Total spend: $0.0014

@M3gA-Mind
M3gA-Mind merged commit b565130 into tinyhumansai:main Oct 23, 2026
11 checks passed
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