Skip to content

Fixed FileStream access to least required permissions - #149

Merged
Crypt32 merged 1 commit into
masterfrom
bug-148
Jul 2, 2026
Merged

Fixed FileStream access to least required permissions#149
Crypt32 merged 1 commit into
masterfrom
bug-148

Conversation

@Crypt32

@Crypt32 Crypt32 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

PR Classification

Code cleanup and minor improvement for file handling.

PR Summary

This pull request consolidates using directives and clarifies file access in the FileUtility class. It improves code readability and ensures explicit file access mode.

  • FileUtility.cs: Consolidated using directives into a single line and added necessary imports.
  • FileUtility.cs: Updated FileStream instantiation to explicitly use FileAccess.Read.

@Crypt32 Crypt32 linked an issue Jul 2, 2026 that may be closed by this pull request
@Crypt32
Crypt32 requested a review from Copilot July 2, 2026 14:33

Copilot AI 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.

Pull request overview

This PR updates FileUtility to open files with explicit read-only access when probing the file header, aligning file handling with least-required permissions and improving clarity around access intent.

Changes:

  • Removes the leading BOM/indentation artifact on the first using line.
  • Updates the header-probe FileStream construction to explicitly use FileAccess.Read.
Comments suppressed due to low confidence (1)

src/Asn1Editor/API/Utils/FileUtility.cs:44

  • The BOM/encoding detection below uses buffer[2] and buffer[3], but the current guard only throws when readBytes < 2. If the file is 2–3 bytes long, the remaining buffer bytes stay 0 (array initialization), which can cause incorrect matches (e.g., UTF-32 check) and misclassify the input. Track readBytes outside the using-block and gate each BOM check by the required byte length (>=3 or >=4).
            Int32 readBytes = fs.Read(buffer, 0, 4);
            if (readBytes < 2) {
                throw new Exception("The data is invalid");
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Crypt32
Crypt32 merged commit d813dc3 into master Jul 2, 2026
3 checks passed
@Crypt32
Crypt32 deleted the bug-148 branch July 2, 2026 14:36
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.

File cannot be opened if only read permission

2 participants