{"record":{"id":"16942752dc07549d","repo":"DrKLO/Telegram","slug":"warning-garbage-data-found-in-jpeg-file","errorCode":null,"errorMessage":"Warning: garbage data found in JPEG file\n","messagePattern":"Warning: garbage data found in JPEG file\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"TMessagesProj/jni/mozjpeg/rdjpgcom.c","lineNumber":156,"sourceCode":"{\n  int c;\n  int discarded_bytes = 0;\n\n  /* Find 0xFF byte; count and skip any non-FFs. */\n  c = read_1_byte();\n  while (c != 0xFF) {\n    discarded_bytes++;\n    c = read_1_byte();\n  }\n  /* Get marker code byte, swallowing any duplicate FF bytes.  Extra FFs\n   * are legal as pad bytes, so don't count them in discarded_bytes.\n   */\n  do {\n    c = read_1_byte();\n  } while (c == 0xFF);\n\n  if (discarded_bytes != 0) {\n    fprintf(stderr, \"Warning: garbage data found in JPEG file\\n\");\n  }\n\n  return c;\n}\n\n\n/*\n * Read the initial marker, which should be SOI.\n * For a JFIF file, the first two bytes of the file should be literally\n * 0xFF M_SOI.  To be more general, we could use next_marker, but if the\n * input file weren't actually JPEG at all, next_marker might read the whole\n * file and then return a misleading error message...\n */\n\nstatic int\nfirst_marker(void)\n{\n  int c1, c2;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/mozjpeg/rdjpgcom.c#L138-L174","documentation":"The next_marker() function in rdjpgcom scans the byte stream for JPEG markers (0xFF followed by a non-zero marker code). If it encounters non-0xFF bytes before finding a marker, it counts them as 'discarded_bytes' and warns the user. This indicates the JPEG stream contains unexpected data between markers -- bytes that are not valid fill bytes or entropy-coded data. The function still continues parsing.","triggerScenarios":"Feeding a corrupted JPEG file to rdjpgcom; a JPEG file with garbage inserted between marker segments; a file that is mostly JPEG but has been concatenated with other data; a truncated file where partial marker data appears as garbage.","commonSituations":"Processing JPEG files that passed through unreliable storage or network transfers; files produced by buggy encoders that insert stray bytes; JPEG files recovered from damaged media; files that have been manipulated or have metadata appended incorrectly.","solutions":["Re-acquire the JPEG file from a trusted source to eliminate corruption.","Use jpegtran or an external tool to re-encode the file, which normalizes the stream: jpegtran -copy none corrupt.jpg > clean.jpg.","Inspect the file with a hex editor to locate and remove the garbage bytes.","If the warning is benign (the file still decodes correctly), suppress stderr output if processing in a pipeline."],"exampleFix":"# Re-encode to normalize the JPEG stream\njpegtran -copy none input.jpg > cleaned.jpg\nrdjpgcom cleaned.jpg","handlingStrategy":"validation","validationCode":"# Validate JPEG structure before processing\nif ! jpegtran -copy none \"$input\" > /dev/null 2>&1; then\n  echo \"Warning: $input may be corrupted\" >&2\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Re-encode JPEG files through jpegtran before processing to normalize streams.","Validate JPEG files with a decoder test before passing to rdjpgcom.","Redirect stderr to /dev/null in pipelines if the warning is non-fatal."],"tags":["jpeg","corruption","parsing","mozjpeg"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}