{"record":{"id":"df7fbe50eee72f9b","repo":"SubtitleEdit/subtitleedit","slug":"unknown-byte-buffer-index-in-subtitle-file","errorCode":null,"errorMessage":"Unknown byte ({buffer[index]}) in subtitle file @ binary offset {index}.","messagePattern":"Unknown byte \\((.+?)\\) in subtitle file @ binary offset (.+?)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/libse/SubtitleFormats/Pac.cs","lineNumber":2521,"sourceCode":"        {\n            var arabicCharacter = GetNextArabicCharacter(buffer, ref index);\n\n            if (arabicCharacter.HasValue && arabicCharacter.Value.SwitchOrder)\n            {\n                // if we have a special character we must fetch the next one and move it before the current special one\n                var tempIndex = index + 1;\n                var nextArabicCharacter = GetNextArabicCharacter(buffer, ref tempIndex);\n                if (buffer[tempIndex] >= 0x80 && nextArabicCharacter != null)\n                {\n                    index = tempIndex;\n                    var combined = $\"{nextArabicCharacter.Value.Character}{arabicCharacter.Value.Character}\";\n                    return combined;\n                }\n            }\n\n            if (ThrowOnError && !arabicCharacter.HasValue)\n            {\n                throw new InvalidOperationException($\"Unknown byte ({buffer[index]}) in subtitle file @ binary offset {index}.\");\n            }\n\n            return arabicCharacter.HasValue\n                ? arabicCharacter.Value.Character\n                : string.Empty;\n        }\n\n        private static SpecialCharacter? GetNextArabicCharacter(byte[] buffer, ref int index)\n        {\n            if (index >= buffer.Length)\n            {\n                return null;\n            }\n\n            var b = buffer[index];\n            SpecialCharacter? arabicCharacter = null;\n            if (ArabicCodes.ContainsKey(b))\n            {","sourceCodeStart":2503,"sourceCodeEnd":2539,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/libse/SubtitleFormats/Pac.cs#L2503-L2539","documentation":"Thrown by Pac.GetArabicString when a byte in the stream does not map to any known Arabic (or combined Arabic) character and the static flag Pac.ThrowOnError is true. Without the flag (the default false) it silently returns an empty string instead. The message reports the offending byte value and the binary offset.","triggerScenarios":"Decoding a PAC file in Arabic codepage where a byte falls outside the Arabic glyph table and cannot be combined with the following byte into a ligature. ThrowOnError=true converts the silent skip into a hard failure for strict validation.","commonSituations":"PAC files with embedded non-Arabic glyphs in an Arabic track, mixed-language content, corrupt glyph bytes, or a codepage misclassification (the file is not actually Arabic).","solutions":["Leave Pac.ThrowOnError at its default false to tolerate unmapped bytes (they become empty).","Verify the file is genuinely an Arabic PAC and not a different language track.","Re-export or re-acquire the PAC file if byte corruption is suspected.","If strictness is required, extend the Arabic code map to cover the offending byte."],"exampleFix":"// before (strict)\nPac.ThrowOnError = true;\n// after (tolerant, default)\nPac.ThrowOnError = false;","handlingStrategy":"validation","validationCode":"// Keep ThrowOnError false (default) so unmapped bytes are skipped, not thrown\nPac.ThrowOnError = false;\nnew Pac().LoadSubtitle(sub, lines, fileName);\n// Set true only for strict one-off audits","typeGuard":null,"tryCatchPattern":"Pac.ThrowOnError = true;\ntry\n{\n    new Pac().LoadSubtitle(sub, lines, fileName);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unknown byte\"))\n{\n    // ex.Message reports the byte value and binary offset\n    logger.Warning(ex.Message);\n}","preventionTips":["Leave Pac.ThrowOnError false for normal loads.","Confirm the file's language is Arabic before decoding.","Re-acquire PAC files from source if bytes look corrupt."],"tags":["subtitle-format","pac","binary","arabic","encoding","byte-mapping"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}