{"record":{"id":"e77191589a8edd83","repo":"SubtitleEdit/subtitleedit","slug":"too-many-bytes-for-ccdata","errorCode":null,"errorMessage":"Too many bytes for CCData!","messagePattern":"Too many bytes for CCData!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"src/libse/Cea708/CcDataSection.cs","lineNumber":52,"sourceCode":"                {\n                    Valid = (bytes[index + i * 3 + 2] & 0b00000100) > 0,\n                    Type = bytes[index + i * 3 + 2] & 0b00000011,\n                    Data1 = bytes[index + i * 3 + 3],\n                    Data2 = bytes[index + i * 3 + 4]\n                };\n            }\n        }\n\n        public CcDataSection(int ccDataCount, byte[] bytes, int sequenceCount)\n        {\n            DataSection = 0x72;\n            ProcessEmData = true;\n            ProcessCcData = true;\n            AdditionalData = true;\n\n            if (bytes.Length / 2 > 16)\n            {\n                throw new Exception(\"Too many bytes for CCData!\");\n            }\n\n            CcData = new CcData[ccDataCount];\n            var bytesIndex = 0;\n            var lastContent = true;\n            for (int i = 0; i < ccDataCount; i++)\n            {\n                if (i == 0)\n                {\n                    CcData[i] = new CcData\n                    {\n                        Valid = true,\n                        Type = 0,\n                        Data1 = 0x80,\n                        Data2 = 0x80,\n                    };\n                }\n                else if (i == 1)","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/Cea708/CcDataSection.cs#L34-L70","documentation":"Thrown by the CEA-708 CcDataSection constructor when the supplied byte array contains more than 16 caption-character pairs (i.e. bytes.Length > 32). Per ATSC A/53 the cc_data block in a picture user-data field holds at most 16 CC pairs per field; exceeding that means the input is malformed or the caller mis-parsed the count.","triggerScenarios":"Passing a raw bytes array larger than 32 to the CcDataSection(int, byte[], int) constructor; ccDataCount not matching bytes.Length/2; feeding concatenated cc_data sections from multiple frames as one.","commonSituations":"Hand-assembled caption packets; buggy upstream ATSC/SEI extractor that did not split cc_data by frame boundary; corrupted transport stream where the SEI payload length is wrong.","solutions":["Verify bytes.Length <= 32 and ccDataCount == bytes.Length/2 before constructing CcDataSection.","Split the incoming payload into <=32-byte cc_data chunks per picture before calling the constructor.","Clamp or truncate oversize buffers with a logged warning instead of throwing.","Regenerate the captions from a trusted source rather than editing raw bytes."],"exampleFix":"// before\nif (bytes.Length / 2 > 16)\n{\n    throw new Exception(\"Too many bytes for CCData!\");\n}\n\n// after\nconst int MaxCcPairs = 16;\nvar usable = Math.Min(bytes.Length / 2, MaxCcPairs);\nif (usable < bytes.Length / 2)\n{\n    Logger.Warn($\"CcData truncated from {bytes.Length / 2} to {MaxCcPairs} pairs.\");\n}\n// proceed using `usable` pairs","handlingStrategy":"validation","validationCode":"if (bytes == null || bytes.Length / 2 > 16 || bytes.Length % 2 != 0) throw new ArgumentException(\"cc_data must be <= 32 bytes and even length\");","typeGuard":null,"tryCatchPattern":"try { var section = new CcDataSection(count, bytes, seq); }\ncatch (Exception ex) when (ex.Message.Contains(\"CCData\")) { /* split or drop packet */ }","preventionTips":["Always split cc_data by picture boundary before constructing sections.","Assert ccDataCount == bytes.Length/2 in unit tests of your encoder."],"tags":["cea708","captions","atsc","validation","subtitle"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}