cuvidParseVideoData may silently corrupt decoder state or memory when SPS/PPS NAL units are omitted or delayed

Summary:

When decoding H.264 via NVDEC and cuvidParseVideoData, omitting SPS/PPS NAL units or submitting them after the first slice NAL can lead to silent corruption of decoder state. This can manifest as severe macroblock artifacts, incorrect output, or in some cases apparent memory corruption without any error return from the API.

Steps to Reproduce:

Encode an H.264 stream using NVENC (baseline, main, or high profile).
Parse the stream and extract only NAL units of type 1 or 5 (slices), omitting types 7 and 8 (SPS/PPS).
Submit each slice individually via cuvidParseVideoData.

Observe decoder behavior:

    Sometimes the stream decodes cleanly (likely due to decoder caching prior config)
    Sometimes the decoded output is severely corrupted (macroblock errors, visual garbage)
    Sometimes the corruption manifests in downstream shared memory consumers

Expected Behavior:

Decoder should return an error if required configuration data (e.g. SPS/PPS) has not been received.
At minimum, internal decoder state should fail gracefully rather than proceeding in an undefined way.

Actual Behavior:

cuvidParseVideoData returns success (CUDA_SUCCESS)
Decoder initializes with garbage state
All slices in the GOP decode incorrectly
In some cases, client applications experience downstream errors (possibly due to corrupted memory structures)

Notes:

Reproducibility is not 100% deterministic; it depends on decoder warm/cold state, and timing.
Once corrupted, the decoder stays in that state until reset.
Fixing the issue by prepending SPS/PPS NALs explicitly resolves all symptoms.

System Configuration:

GPU: Seen on 4080 and 1650
Driver Version: 572.83
CUDA Version: 12.3
Codec SDK: 12.1.14   
Windows 11

Further note:

We control both encoding and parsing - this is not a malformed stream, just a malformed decode setup (our NAL parser) that the API allows without warning.

“this is not a malformed stream, just a malformed decode setup”

It is in fact malformed stream. Absense of SPS makes decoding impossible generally.

Yes. I makes a valiant effort and often looks fine. Sometimes it looks very blocky, which is what raised my suspicions in the first place that something was wrong with my NAL parser. Anyway, cuvidParseVideoData doesn’t report an error and trashes my process’s memory, leading to inexplicable and strange bugs. Fixing the NAL parser to provide the correct data fixed the strange bugs.

Looking fine is not enough, it should be decoded bitperfect.

Yes this is not the point is it. The point is cuvidParseVideoData trashes process memory, preferring not to do any validation internally (apparently).