You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add GifCodec (decode-only) with real-world GIF fixture tests - #19
Adds a new decode-only GifCodec supporting GIF87a/GIF89a parsing, following the same public API shape as BmpCodec/PngCodec/TiffCodec/JpegCodec: Load(Stream), Load(string), GetInfo(Stream), GetInfo(string). No Save - GIF is decode-only in this codec.
Key design points
GetInfo/Load parity: both share a single private ReadLogicalScreenDescriptor(Stream) method as their first step, so header parsing/limits cannot drift out of sync (per prior JPEG PR feedback).
GIF-native LZW decoder: a new LSB-first bit-packed LZW decoder (GIF's bit order/code-value scheme differs from TIFF's), with standard (non-early-change) code-size growth, KwKwK reconstruction, and tolerant table-overflow handling.
Transparency: Graphic Control Extension transparent color index is read from data[3] (byte0=packed fields, byte1-2=delay time LE [ignored], byte3=transparent color index).
First-frame-only decode: multi-frame/animated GIFs decode only the first Image Descriptor's frame; subsequent frames are validated/skipped. CanDecode remains rue (default) since a well-formed animated GIF isn't malformed merely because this codec decodes only its first frame - documented in XML remarks.
Interlace de-mux: standard 4-pass GIF interlace row ordering.
Sub-region (Image Descriptor left/top/width/height) blitting onto the Logical Screen Descriptor canvas, with full bounds validation.
Companion artifacts
Design doc: docs/design/canvas-net/codecs/gif-codec.md (+ registration in codecs.md/introduction.md)
Reqstream: docs/reqstream/canvas-net/codecs/gif-codec.yaml (+ registration in codecs.yaml/
equirements.yaml)
User docs: README.md snippet, docs/user_guide/introduction.md new ### GifCodec section
.cspell.yaml: additive new technical terms only
Fixtures
8 real-world GIF files from https://samplelib.com/sample-gif.html (unrestricted license - no attribution required, see GifFixtures/README.md), covering solid-color single-frame and animated multi-frame GIFs at multiple resolutions. Solid-color fixture tests read each file's actual Global Color Table bytes directly rather than hardcoding assumed RGB values.
Verification
pwsh ./fix.ps1 (auto-fixers)
pwsh ./build.ps1 - build succeeded, 0 warnings/errors, full test suite passing across net8.0/net9.0/net10.0
pwsh ./lint.ps1 - all clean (spelling, markdown, YAML, sysml2tools model validation, reqstream/reviewmark lint, dotnet format)
Independent quality-agent code review confirmed correctness of the GCE offset, LZW decoder semantics, interlace de-mux pattern, and companion-artifact completeness.
Adds a new decode-only GifCodec supporting GIF87a/GIF89a parsing: shared
header parsing (ReadLogicalScreenDescriptor) for GetInfo/Load parity, global
and local color tables, Graphic Control Extension transparency (data[3]),
Image Descriptor sub-region blitting with interlace de-mux, and a
GIF-native LSB-first LZW decoder. Only the first frame of multi-frame/
animated GIFs is decoded; CanDecode remains true by design.
Includes companion design/reqstream/verification/sysml2 documentation,
.reviewmark.yaml review-set registration, hand-authored malformed-input
tests, and conformance tests against 8 real-world GIF fixtures
(solid-color and animated) sourced from samplelib.com (unrestricted
license, see GifFixtures/README.md).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🟡 Changes recommended
Address decoder validation and resource-bounding concerns, add local-color-table coverage, and correct stale documentation and requirements traceability.
Get a fresh assessment by requesting another Copilot review.
…udget, LCT-only test coverage
Resolves 7 low-severity findings from the Copilot code review on PR #19:
- DecodeGifLzw now continues until an actual End-of-Information code is read (never
stops early merely because the declared pixel count was reached), and rejects any
code that would decode past exactly that count, instead of silently truncating.
- ReadSubBlocks now enforces a shared 64 MiB total budget (MaxTotalSubBlockBytes,
internal for test-seam access matching the JpegCodec precedent) across every
extension and Image Descriptor sub-block chain in a file, bounding memory even for
tiny-dimension GIFs with pathological sub-block counts.
- Added GifCodec_Load_LocalColorTableOnly_DecodesExpectedPixels, positively exercising
the existing first-frame-Local-Color-Table-only decode path.
- Added GifCodec_Load_LzwStreamMissingEoi_ThrowsInvalidDataException and
GifCodec_Load_LzwStreamOverrunsExpectedCount_ThrowsInvalidDataException.
- Added GifCodec_Load_ExcessiveSubBlockData_ThrowsInvalidDataException, proving the new
sub-block budget is enforced.
- Design docs, NamespaceDoc, and reqstream/verification companion artifacts updated to
stop claiming GifCodec is bidirectional, close an orphaned-requirements traceability
gap for the new system-level GIF Codec API section, and add unit requirements/tests
for the sub-block budget and LZW EOI/overrun strictness.
- Added CanvasNet_SystemIntegration_GifLoad_ReturnsExpectedPixel system-integration test.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
GIF Graphic Control Extensions have one fixed-size data sub-block of exactly 4 bytes followed by the terminator. ReadSubBlocks concatenates arbitrary sub-blocks, so a malformed 0x02 ... 0x02 ... 0x00 GCE totaling four bytes is accepted and applied as valid transparency metadata. Read the first size byte separately and reject any size other than 4 (and any additional data sub-block) before parsing the four fields.
This issue also appears in the following locations of the same file:
line 233
line 446
Update codec count in shared ImageInfo documentation
Adding GIF to this list leaves the later shared-type explanation saying that “all four codecs” report the properties (lines 62-63), which is now stale and contradicts this five-codec list. Update that count so the public ImageInfo documentation consistently covers all six codecs, including the decode-only SVG codec where applicable.
…ystem layer
The initial 'GIF Codec API' system-level section linked CanvasNet-Lib-Gif* directly
to unit-level CanvasNet-Codecs-GifCodec-* requirements, bypassing the existing
subsystem-level CanvasNet-Codecs-Gif* requirements in codecs.yaml (the same pattern
CanvasNet-Lib-JpegLoad etc. already use), which caused CI's reqstream --enforce
orphan check to fail on those 6 pre-existing subsystem requirements.
- canvas-net.yaml: CanvasNet-Lib-Gif* children now point to the subsystem-level
CanvasNet-Codecs-Gif* requirements, matching every other codec's system section.
- codecs.yaml: added the new LzwRequiresEoi/SubBlockBudget unit requirements as
children of CanvasNet-Codecs-GifUnsupportedFormatValidation (with their tests),
and added GifCodec_Load_LocalColorTableOnly_DecodesExpectedPixels to
CanvasNet-Codecs-GifLoad's tests list.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The shared header parser does not reject a zero logical-screen width or height, so GetInfo returns an ImageInfo for a malformed 0xN GIF while Load rejects the same header at lines 153-156. The other codec header parsers validate non-positive dimensions even when max-dimension enforcement is disabled; apply the positive-dimension check in this shared parser so GetInfo does not accept a malformed GIF header.
Update shared codec documentation to include GifCodec
The new paragraph correctly updates the list to five raster codecs, but the following shared description still says that "all four codecs" report the four properties (around ImageInfo.cs:62-63). This leaves the public XML documentation internally inconsistent after adding GifCodec; update the remaining count and related wording to include the new raster codec.
Fixes 5 legitimate findings surfaced by an automated re-review of the
previous fix commits:
- Correct a second stale bidirectional/Save claim in
docs/design/canvas-net/codecs.md (five raster codecs -> four of the
five, all but the decode-only GifCodec).
- Fix CanvasNet-Lib-GifGetInfo/GifGetInfoValidation test evidence in
docs/reqstream/canvas-net.yaml, which referenced the system
integration test (which never calls GetInfo) instead of the actual
focused GifCodec_GetInfo_* unit tests.
- Update docs/verification/canvas-net/codecs.md, which still claimed
GifCodec had no system-integration test coverage.
- Rewrite MaxTotalSubBlockBytes' doc comment in GifCodec.cs to stop
overclaiming that no legitimate file at MaxDimension could ever
exceed the 64 MiB sub-block budget; a pathological (not just
malicious) encoder could in principle do so, and this tradeoff is
now documented honestly instead of asserted away.
- Fix a real validation gap in GifCodec.Load: the local/global color
table presence check was nested inside if (result is null), so
only the first frame's Image Descriptor was validated to have a
resolvable color table. A later frame with neither a Local nor
Global Color Table was silently accepted even though this codec
never decodes that frame's pixel data. The check now runs for every
Image Descriptor.
Adds GifCodec_Load_SecondFrameMissingColorTable_ThrowsInvalidDataException
to prove the fix, and updates the CanvasNet-Codecs-GifCodec-NoColorTable
unit requirement (title, justification, tests) plus its subsystem-level
test list and verification doc subsection accordingly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This returns CanDecode == true for a GIF whose Logical Screen Descriptor has a zero width or height, but Load rejects the same header at lines 163-166. Since zero dimensions are invalid within the header (and other codecs reject them in GetInfo), validate non-positive dimensions here while continuing to report oversized positive dimensions raw; otherwise the documented GetInfo/Load contract is broken.
Correct opaque pixel requirement for transparent GIF pixels
This requirement says every decoded GIF pixel has fully opaque alpha, but the implementation and the linked transparency requirement intentionally produce alpha 0 for the active Graphic Control Extension's transparent index. Leaving the Load requirement as written makes the requirements set contradict the public behavior and its verification.
The new count is updated to five raster codecs here, but the later shared remarks still say that 'all four codecs' report the same properties (line 63). Please update that stale count as part of this GIF addition so the generated API documentation does not contradict itself.
Fixes the last outstanding review finding: ReadSubBlocks' generic
concatenating reader let a Graphic Control Extension's 4 required data
bytes be split across multiple sub-blocks (e.g. two 2-byte sub-blocks)
and still be silently accepted, since only the reassembled total
length was checked. This is not spec-compliant: GIF89a requires the
Graphic Control Extension's data to be exactly one 4-byte sub-block
immediately followed by the block terminator.
Adds a dedicated ReadGraphicControlExtensionData helper that reads the
single declared sub-block size (rejecting anything other than 4),
reads exactly 4 bytes, and then requires the very next byte to be the
zero-length block terminator (rejecting any further sub-block data) -
leaving the generic ReadSubBlocks reader in place, unchanged, for every
other extension type and for image data, where multi-sub-block
chaining remains legitimate.
Adds GifCodec_Load_FragmentedGraphicControlExtension_ThrowsInvalidDataException
and updates the CanvasNet-Codecs-GifCodec-MalformedGraphicControlExtension
unit requirement (title, justification, tests) and its verification doc
subsection accordingly.
Also fixes a stale codec count in ImageInfo.cs's shared doc comment
('all four codecs' -> 'all five raster codecs'), left inconsistent
after GifCodec was added to the codec list earlier in this remarks
block but not to this later summary sentence.
Verified via local ReqStream --enforce: 0 orphaned requirements (the
6-orphan regression from an earlier push was already fixed and
reverified here); dotnet test (4089 tests, all passing); fix.ps1 and
lint.ps1 both clean.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This requirement contradicts the implementation and the separate transparency requirement: it names only a Global Color Table and requires fully opaque alpha, while GifCodec also supports Local Color Tables and sets alpha to zero for the active Graphic Control Extension's transparent index. Reword the requirement so the traceability contract covers both supported table types and the transparency exception.
ReadGraphicControlExtensionData decremented the shared remainingBudget
by its fixed 4-byte payload without first checking that 4 bytes were
actually still available, unlike ReadSubBlocks. If preceding
extension/image data had already exhausted (or nearly exhausted) the
budget, a Graphic Control Extension could still drive remainingBudget
negative and be accepted, and repeated Graphic Control Extensions
could continue to do so past the advertised MaxTotalSubBlockBytes
limit - meaning the total sub-block bound was not actually enforced
for this block type.
Fixed by checking size > remainingBudget and throwing
InvalidDataException before decrementing, exactly as ReadSubBlocks
already does.
Adds
GifCodec_Load_GraphicControlExtensionExceedsRemainingSubBlockBudget_ThrowsInvalidDataException,
which exhausts all but 2 bytes of the shared budget via a preceding
Comment Extension and then supplies an otherwise well-formed 4-byte
Graphic Control Extension, asserting it is now rejected. Updates the
CanvasNet-Codecs-GifCodec-SubBlockBudget unit requirement (title,
justification, tests) and its verification doc subsection
accordingly.
Verified via dotnet test (4092 tests, all passing), local ReqStream
--enforce (0 orphaned requirements), fix.ps1, and lint.ps1 (all
clean).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
minCodeSizeByte is validated only when the first frame reaches DecodeGifLzw; later descriptors merely buffer and discard it. Consequently a multi-frame GIF with a later LZW minimum code size of 0 or 9 is accepted even though GIF requires 2-8 and the Load contract says invalid LZW data is rejected. Validate this field before skipping subsequent frames (and add a regression case).
Reject zero GIF logical screen dimensions in GetInfo
The shared header parser accepts a zero width or height, so GetInfo returns CanDecode == true for a malformed 0xN GIF while Load rejects the exact same 13-byte header at lines 163-166. The other codec header parsers validate non-positive dimensions even when max-dimension enforcement is disabled (for example PngCodec.cs:1777-1780); apply the same validation here so both entry points reject an invalid Logical Screen Descriptor.
…imension GetInfo
- Validate the LZW minimum code size byte (2-8) for every Image Descriptor in
GifCodec.Load, not just the first frame that DecodeGifLzw range-checks.
- Reject a zero width or height Logical Screen Descriptor in GifCodec.GetInfo,
matching the identical check Load already performs, while still not
enforcing Surface.MaxDimension in GetInfo.
- Add unit tests for both new validation paths.
- Update reqstream (unit/subsystem/system level) and verification/design docs
to reflect the new validation behaviors.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Address the decoder validation and interlace-test issues, along with documentation and traceability inconsistencies.
Review effort: Lite Findings: None
Previously missed (3)
In code that hasn't changed since last review
Add empty-path test evidence to GIF load requirement
docs/reqstream/canvas-net.yaml:837
This system requirement claims that GIF load rejects an empty path, but its only listed test is CanvasNet_SystemIntegration_GifLoad_ReturnsExpectedPixel, which never passes an empty path. The focused GifCodec_Load_EmptyPath_ThrowsArgumentException test already exists; list it here (or add a system-level invalid-path test) so this requirement has matching evidence, as the neighboring GetInfo requirements do.
Align null-argument requirement scope with Load validation
docs/reqstream/canvas-net/codecs.yaml:766
This requirement is titled as covering null arguments to both Load and GetInfo, and its evidence lists the GetInfo null tests, but its only child requirements are LoadNullStream and LoadNullPath. The GetInfo validation is decomposed under the separate GifGetInfoValidation requirement, so narrow this requirement and its evidence to Load (as the sibling codec requirements do) or add a consistent child decomposition.
Qualify opaque-pixel requirement for GIF transparency
This unit requirement says every decoded pixel has fully opaque alpha, but the implementation intentionally sets alpha to 0 for the active Graphic Control Extension's transparent index (GifCodec.cs:307-309), and the adjacent TransparentColorIndex requirement documents that behavior. Qualify this requirement so it describes opaque pixels except where GIF transparency applies.
- Add GifCodec_Load_EmptyPath_ThrowsArgumentException evidence to the
system-level CanvasNet-Lib-GifValidationEmptyPath requirement, which
previously only cited the unrelated system-integration Load test.
- Narrow CanvasNet-Codecs-GifValidationNull to Load-only null-argument
validation (title, justification, tests), matching the sibling
Bmp/Png/Jpeg codec pattern where GetInfo's null validation is
decomposed separately under CanvasNet-Codecs-GifGetInfoValidation.
- Qualify CanvasNet-Codecs-GifCodec-Load's title so decoded pixels are
described as opaque except where GIF transparency applies, removing
the contradiction with CanvasNet-Codecs-GifCodec-TransparentColorIndex.
This design description says every extension, including a Graphic Control Extension, is read through ReadSubBlocks, but the implementation intentionally uses the stricter ReadGraphicControlExtensionData path for GCEs and only uses ReadSubBlocks for other extensions and image data. Please update the design text so it does not document a helper path the implementation does not use.
Add GCE budget regression to subsystem evidence
docs/reqstream/canvas-net/codecs.yaml:829
The subsystem requirement lists CanvasNet-Codecs-GifCodec-SubBlockBudget as a child, whose unit evidence includes both budget tests, but its tests list records only the generic excessive-sub-block case. The dedicated GCE budget regression is therefore omitted from the subsystem-level evidence; add GifCodec_Load_GraphicControlExtensionExceedsRemainingSubBlockBudget_ThrowsInvalidDataException alongside the existing test.
Document total sub-block limit in exception contract
The new shared sub-block budget is an intentional Load failure mode, but the public XML exception contract lists malformed LZW/data conditions without mentioning that a file exceeding MaxTotalSubBlockBytes is rejected. Add the total sub-block limit here so callers are not surprised when a structurally valid GIF is refused for the documented resource bound.
…ce, document sub-block budget in exception contract
- Correct gif-codec.md design doc: GCEs are parsed via the dedicated
fixed-size ReadGraphicControlExtensionData path, not the general
ReadSubBlocks chain used for other extensions/image data.
- Add GifCodec_Load_GraphicControlExtensionExceedsRemainingSubBlockBudget_ThrowsInvalidDataException
to the CanvasNet-Codecs-GifCodecLoad subsystem requirement's tests list
in docs/reqstream/canvas-net/codecs.yaml, matching the unit-level
evidence in docs/reqstream/canvas-net/codecs/gif-codec.yaml.
- Document the MaxTotalSubBlockBytes rejection case in the Load method's
InvalidDataException XML doc remarks.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Unresolved moderate findings remain in GIF87a coverage, descriptor validation order, and fixture parity testing.
Review effort: Lite Findings: None
Previously missed (1)
In code that hasn't changed since last review
Missing null argument tests as verification evidence
docs/reqstream/canvas-net.yaml:823
This system requirement is specifically about rejecting null stream/path arguments, but its only listed evidence is the successful-pixel integration test, which never passes null. Link the existing GifCodec_Load_NullStream_ThrowsArgumentNullException and GifCodec_Load_NullPath_ThrowsArgumentNullException tests here, as the child subsystem requirement already does, so the requirement has accurate verification evidence.
This issue also appears on line 857 of the same file.
…lidation requirement
CanvasNet-Lib-GifValidationNull (system-level) previously cited only the
successful-pixel integration test as verification evidence for a
requirement specifically about rejecting null stream/path arguments.
Link the existing focused tests GifCodec_Load_NullStream_ThrowsArgumentNullException
and GifCodec_Load_NullPath_ThrowsArgumentNullException, matching the
pattern already used by the child subsystem-level requirement
CanvasNet-Codecs-GifValidationNull in docs/reqstream/canvas-net/codecs.yaml.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Address the documented GIF87a coverage gap and correct resource-limit wording and requirements evidence.
Review effort: Lite Findings: None
Previously missed (2)
In code that hasn't changed since last review
Remove unsupported empty-path evidence or add a matching test
docs/reqstream/canvas-net.yaml:839
This evidence list includes CanvasNet_SystemIntegration_GifLoad_ReturnsExpectedPixel, but that test only loads a valid 1x1 stream and never passes an empty path. The root requirement therefore claims evidence it does not have; keep only the focused empty-path test (or add a test that actually exercises this system requirement).
Link root requirement to malformed-input verification tests
docs/reqstream/canvas-net.yaml:858
The root unsupported-format requirement is linked only to a successful-load integration test, which cannot demonstrate any of the listed InvalidDataException cases. Replace this placeholder with the focused GIF malformed-input tests already listed under CanvasNet-Codecs-GifUnsupportedFormatValidation, so the root requirement's verification evidence is truthful.
- CanvasNet-Lib-GifValidationEmptyPath: remove irrelevant
CanvasNet_SystemIntegration_GifLoad_ReturnsExpectedPixel evidence (which
only exercises a valid 1x1 GIF, never an empty path), keeping the
focused GifCodec_Load_EmptyPath_ThrowsArgumentException test.
- CanvasNet-Lib-GifUnsupportedFormatValidation: replace the same
successful-load evidence (incapable of demonstrating
InvalidDataException) with the full set of focused malformed-input
tests already used as evidence for the child subsystem requirement
CanvasNet-Codecs-GifUnsupportedFormatValidation in codecs.yaml, matching
the pattern used by the sibling Bmp requirement.
"Fully parsed and validated" overstates what the implementation does for later frames: it validates their descriptors, tables, dimensions, minimum code size, and sub-block framing, but intentionally does not validate LZW codes or palette indices. Say structurally validated so the design does not promise semantic validation that is not performed.
…ation
- Design doc: add cumulative sub-block budget (MaxTotalSubBlockBytes) to
Load's documented InvalidDataException conditions.
- Design doc: reword later-frame validation from 'fully parsed and
validated' to 'structurally validated', clarifying LZW codes and
palette indices are not semantically validated for frames after the
first.
- User guide: complete the Load(Stream) InvalidDataException list with
the LZW minimum code size range check, exact-output-count/EOI
validation, and the cumulative sub-block budget limit.
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
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.
Summary
Adds a new decode-only GifCodec supporting GIF87a/GIF89a parsing, following the same public API shape as BmpCodec/PngCodec/TiffCodec/JpegCodec: Load(Stream), Load(string), GetInfo(Stream), GetInfo(string). No Save - GIF is decode-only in this codec.
Key design points
Companion artifacts
equirements.yaml)
Fixtures
8 real-world GIF files from https://samplelib.com/sample-gif.html (unrestricted license - no attribution required, see GifFixtures/README.md), covering solid-color single-frame and animated multi-frame GIFs at multiple resolutions. Solid-color fixture tests read each file's actual Global Color Table bytes directly rather than hardcoding assumed RGB values.
Verification
pwsh ./fix.ps1(auto-fixers)pwsh ./build.ps1- build succeeded, 0 warnings/errors, full test suite passing across net8.0/net9.0/net10.0pwsh ./lint.ps1- all clean (spelling, markdown, YAML, sysml2tools model validation, reqstream/reviewmark lint, dotnet format)Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com