Skip to content

Make the tellg failure check explicit and document the EPContext write gate error handling - #31196

Open
GopalakrishnanN wants to merge 1 commit into
mainfrom
GopalakrishnanN/epcontext-helper-file-gate-followup
Open

Make the tellg failure check explicit and document the EPContext write gate error handling#31196
GopalakrishnanN wants to merge 1 commit into
mainfrom
GopalakrishnanN/epcontext-helper-file-gate-followup

Conversation

@GopalakrishnanN

Copy link
Copy Markdown
Contributor

Description

Two follow-ups from automated review of the EPContext sample helper, both no-functional-change.

1. tellg() failure check. The file-size read held the result in a std::streampos and compared it with 0, which works only through the implicit fpos to streamoff conversion. Holding it in a std::streamoff makes it a plain integral comparison against the documented pos_type(-1) failure value.

2. Documented the error_code handling in EnsureRegularFileForWrite. A reviewer flagged that a failing symlink_status falls through and skips the symlink check, and suggested failing closed. I verified the behavior before changing anything, and did not apply that fix, because it would break the common path:

case error_code file_type
missing file in an existing dir (normal new-file write) set (2) not_found
missing parent directory set (3) not_found
invalid name (a genuine error) set (123) not_found
existing regular file clear regular

On MSVC a simply-missing target sets error_code, so failing closed on any error would reject ordinary new-file writes. Comparing against std::errc::no_such_file_or_directory does not separate the cases either: ERROR_INVALID_NAME maps to that same condition, so a genuine error is indistinguishable from a benign absent path by either the code or the type.

The residual exposure is small: a target whose type cannot be determined fails at the ofstream open anyway. So the existing fall-through is deliberate, and this adds a short comment recording that rather than changing the guard.

Motivation and Context

This file is sample/reference code EP authors are expected to copy, so a subtly non-obvious guard is worth documenting, and a comparison that relies on an implicit conversion is worth making explicit.

Follow-up to #29294. Raised by automated review on #31195, where the comments landed on a stale diff.

Verified: clang-format clean, within 120 columns, onnxruntime_autoep_test builds, and the EpContextDataUtils tests pass (11 passed, 2 skipped - both symlink tests, which need privileges on Windows).

…or_code handling

Two follow-ups from automated review of the EPContext sample helper. First, the file-size read held tellg() in a std::streampos and compared it with 0, which works only through the implicit fpos to streamoff conversion; holding it in a std::streamoff makes that a plain integral comparison against the documented pos_type(-1) failure value. Second, a note on EnsureRegularFileForWrite explaining why a set error_code falls through to allow the write instead of failing closed. Verified on MSVC that a simply-missing target sets error_code (value 2) rather than only reporting file_type not_found, so failing closed on any error would reject the ordinary new-file write, which is the common path. Comparing against errc no_such_file_or_directory does not separate the cases either, since ERROR_INVALID_NAME maps to the same condition. A target whose type cannot be determined fails at the open regardless. No functional change.
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