Conversation
Real-world OFD files (invoice generators in particular) hit three parsing/rendering dead ends; every failure below also reproduces in deepin-reader since it links the same library: - rofd-core: accept several <MultiMedias> blocks in one resource catalog (mirrors the existing Fonts handling) instead of failing with a serde duplicate-field error; strict mode still rejects them - rofd-core: treat an empty <Clips/> element as absent in lenient mode instead of rejecting the whole page; strict mode still errors - rofd-render: decode images by their detected byte signature rather than the catalog-declared format (invoices declare PNG for JPEG data); unsupported signatures are still rejected With these, 6/6 real invoice OFDs render (2/6 before). Regression tests added for all three; existing suites updated where the old strictness was asserted.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe PR hardens OFD parsing and rendering against common invoice-producer deviations by merging repeated resource blocks and tolerating empty clipping containers in lenient mode, while retaining strict-mode validation. Image decoding now trusts supported byte signatures over potentially incorrect declared formats, with regression tests covering each compatibility behavior. Sequence diagram for image format sniffing during renderingsequenceDiagram
participant Renderer
participant Preflight
participant ImageResource
participant Decoder
Renderer->>Preflight: preflight(resource, limits)
Preflight->>ImageResource: asset_path()
Preflight->>Preflight: detect_format(resource)
Preflight->>Decoder: Decode using detected byte signature
Decoder-->>Preflight: Decoded image
Preflight-->>Renderer: Rendering source
Flow diagram for lenient and strict OFD compatibility handlingflowchart TD
A[Parse OFD resources and page content] --> B{Duplicate MultiMedias blocks?}
B -->|No| C[Build ResourceCatalog]
B -->|Lenient| D[Merge MultiMedias entries]
B -->|Strict| E[Reject duplicate MultiMedias]
D --> C
A --> F{Empty Clips element?}
F -->|No| G[Process clipping paths]
F -->|Lenient| H[Treat Clips as absent]
F -->|Strict| I[Reject invalid Clips]
H --> J[Render page]
G --> J
C --> J
E --> K[Parse failure]
I --> K
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
真实世界的 OFD 文件(发票生成器尤为典型)会触发三处解析/渲染死路;由于 deepin-reader 链接同一套库,以下失败在阅读器中同样复现:
<MultiMedias>目录,serde 报 duplicate field 直接失败。改为与 Fonts 块相同的处理:lenient 模式合并(Option<T>→Vec<T>),strict 模式仍然拒绝<Clips/>元素:lenient 模式视为无裁剪继续渲染,strict 模式保持报错修复前 6 张真实报销发票仅 2 张可渲染,修复后 6/6 全部正常。
测试
cargo test -p rofd-core -p rofd-render全量通过;cargo clippy --all-targets -- -D warnings干净Summary by Sourcery
Make OFD parsing and rendering resilient to common producer inconsistencies while retaining strict validation options.
Bug Fixes:
Enhancements:
Tests: