Skip to content

Fix file extension mismatch detection logic false positives and negatives#77

Merged
justnullname merged 6 commits intomainfrom
fix-extension-mismatch-6362394628477913948
Mar 20, 2026
Merged

Fix file extension mismatch detection logic false positives and negatives#77
justnullname merged 6 commits intomainfrom
fix-extension-mismatch-6362394628477913948

Conversation

@justnullname
Copy link
Owner

The issue requested fixing the file extension mismatch detection logic which was failing to display the correction icon (warning) on certain mismatched files or displaying it erroneously on correct ones.

Problem

The CheckExtensionMismatch logic in QuickView/main.cpp relied on fmt.contains(rule.format) evaluated linearly down the g_formatRules array. This resulted in cases where a valid format like WBMP incorrectly triggered the BMP rule because "wbmp".contains("bmp") evaluates to true. Furthermore, some format strings provided by the image decoder backend like jpeg xl, tinyexr, or libavif were previously incorrectly stored as valid extensions in the array, making it impossible to detect if .jpg was mismatched as .jxl because it would match earlier rules or fail incorrectly.

Solution

  1. Prioritized Exact/Compound Formats: Extracted specific and compound format names (e.g., wbmp, jpeg xl, tinyexr) and placed them at the top of the g_formatRules array. This prevents a substring match on shorter names like bmp or jpeg from triggering falsely.
  2. Fixed Invalid Aliases: Converted incorrect extension aliases (like L"libavif") into proper format-matching entries with their respective primary extensions (like .avif).
  3. Expanded Alternatives: Added alt4 and alt5 fields to the FormatExtRule struct to support file format families with many extensions (e.g. the TGA family .tga, .icb, .vda, .vst or the PNM family .pnm, .pgm, .ppm, .pbm).
  4. Compatibility Check: Substituted fmt.contains(...) with fmt.find(...) != std::wstring::npos to ensure better compatibility with C++17 while maintaining the same behavior.

PR created automatically by Jules for task 6362394628477913948 started by @justnullname

- Expanded `FormatExtRule` struct to support up to `alt5` alternatives to handle formats with many file extensions (e.g. PNM and TGA).
- Reordered `g_formatRules` to evaluate compound and specific format strings (like "wbmp", "jpeg xl", "tinyexr", "libavif") before core formats (like "bmp", "jpeg", "exr"). This fixes false positive mismatch warnings where "wbmp" incorrectly matched the "bmp" rule via substring check.
- Refactored matching loop to safely handle multiple alt conditions.
- Downgraded `fmt.contains` to `fmt.find(...) != std::wstring::npos` for better compiler compatibility without altering logic.
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

justnullname and others added 5 commits March 20, 2026 04:17
- Expanded `FormatExtRule` struct to support up to `alt5` alternatives to handle formats with many file extensions (e.g. PNM and TGA).
- Reordered `g_formatRules` to evaluate compound and specific format strings (like "wbmp", "jpeg xl", "tinyexr", "libavif") before core formats (like "bmp", "jpeg", "exr"). This fixes false positive mismatch warnings where "wbmp" incorrectly matched the "bmp" rule via substring check.
- Refactored matching loop to safely handle multiple alt conditions.
- Downgraded `fmt.contains` to `fmt.find(...) != std::wstring::npos` for better compiler compatibility without altering logic.
- Fixed `ImageEngine` missing propagation of `formatDetails` for SVGs across FastLane and `SafeCacheFrame` cache copies, preventing missing metadata downstream.
…adata for fast formats

- Fix the constructor of `Toolbar` where the `FixExtension` button warning flag was hard-coded to `true` but skipped during layout, causing it to have a `0, 0, 0, 0` rect.
- Added explicit call to `g_toolbar.UpdateLayout` immediately after `SetExtensionWarning` runs so the UI recalculates the bounds of the warning icon and it actually displays on screen when an extension is mismatched.
- Fixed missing `formatDetails` string deep copy for SVG frames inside the `ImageEngine.cpp` FastLane processing to ensure accurate metadata is passed to the user interface.
- Correctly default `FixExtension` button `isWarning` flag to `false` so the UI knows it is hidden initially.
- Automatically call `g_toolbar.UpdateLayout` immediately after `SetExtensionWarning` assigns warning state, fixing the `{0,0,0,0}` button rect bug where the error icon would never be drawn even when correctly detected.
- Fixed `ImageLoader::LoadToFrame` missing metadata output `formatDetails` assignment for SVG files.
- Extended `FormatExtRule` array and structurally reorganized format string rules to evaluate exact and compound format strings before shorter matches to prevent substring detection false positives.
@justnullname justnullname merged commit 54c8b08 into main Mar 20, 2026
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