Skip to content

Address the Codacy findings on #6 (TIFF/EMF/WMF tests, input validation) - #7

Merged
davidnmbond merged 1 commit into
mainfrom
fix/codacy-findings-pr6
Oct 13, 2026
Merged

davidnmbond merged 1 commit into
mainfrom
fix/codacy-findings-pr6

Conversation

@davidnmbond

Copy link
Copy Markdown

Codacy's analysis of #6 raised 7 new issues (2 high). This addresses the actionable ones.

  • ImageHeaderReader (TIFF): an unsupported field type on a required field (width/height) now throws InvalidDataException; optional resolution fields fall back to 96 dpi; other tags have an explicit default branch; a TIFF without width and height is rejected.
  • ExcelDrawings.AddPicture(FileInfo): throws ArgumentNullException instead of a bare Exception.
  • ExcelHeaderFooter.InsertPicture: validates the image before the picture placeholder is appended to the section text, so rejected data leaves nothing behind; null FileInfo guarded.
  • Tests (new, cross-platform): TIFF in both byte orders, centimetre resolution, missing/optional/required fields, truncated and wild offsets; EMF and WMF sizes and truncation; InsertPicture from bytes, stream and file, duplicate section, invalid data and null arguments.

Not changed: Codacy also flagged the removed test exclusions in ci.yml ("re-enables documented failures"). That is a false positive: the exclusions were removed because their root causes were fixed in #6, and the Linux CI run passes with none.

Verified locally: full suite 1199 passed, 0 failed, 214 skipped.

🤖 Generated with Claude Code

- ImageHeaderReader TIFF: an unsupported field type on a required field
  (width/height) is now rejected with InvalidDataException, optional resolution
  fields fall back to the default DPI, unrelated tags have an explicit default
  branch, and a TIFF without a width and height is rejected.
- ExcelDrawings.AddPicture(FileInfo): throw ArgumentNullException, not Exception.
- ExcelHeaderFooter.InsertPicture: validate the image before ValidateImage appends
  the picture placeholder to the section text, so rejected data leaves no
  placeholder behind; guard the FileInfo overload against null.
- New tests: TIFF (both byte orders, cm units, missing/optional/required fields,
  truncated and wild offsets), EMF, WMF, and the InsertPicture overloads
  (bytes, stream, file, duplicate section, invalid data, null arguments).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 31 complexity · 0 duplication

Metric Results
Complexity 31
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.31% coverage variation

Metric Results
Coverage variation ✅ +0.31% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (22a7e64) 47272 30474 64.47%
Head commit (1839c9f) 47464 (+192) 30745 (+271) 64.78% (+0.31%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7) 201 201 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production 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.

Pull Request Overview

👀 Worth a closer look

Malformed TIFF offsets may escape the image-reader contract as overflow or range exceptions instead of InvalidDataException; this warrants review before relying on the stated validation behavior. ImageHeaderReader is also relatively complex, though existing coverage is strong and no uncovered complex files were reported.

1 comment outside of the diff
PanoramicData.EPPlus/Compatibility/ImageHeaderReader.cs

line 202 🟡 MEDIUM RISK
Suggestion: Consider extracting TIFF entry decoding and/or IFD traversal into focused private helpers while preserving required dimension validation and optional resolution fallback.

Test suggestions

  • TIFF parsing in little- and big-endian byte order
  • TIFF centimetre resolution conversion
  • TIFF missing dimensions and unsupported required/optional field types
  • TIFF truncation and invalid offsets
  • EMF dimensions and truncation handling
  • WMF dimensions, custom units, and truncation handling
  • Header/footer picture insertion from bytes, streams, and files
  • Duplicate-section, invalid-image, and null-argument validation
  • ExcelDrawings.AddPicture null FileInfo validation

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment on lines +222 to +224
return required
? throw new InvalidDataException($"Unsupported TIFF field type {type} for a required field")
: 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

Validate the TIFF value offset and required byte range against the input length before reading, and translate invalid offsets or ranges into InvalidDataException.

@davidnmbond
davidnmbond merged commit c6c2c95 into main Oct 13, 2026
7 checks passed
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