DrKLO/Telegram · warning
Warning: garbage data found in JPEG file
Error message
Warning: garbage data found in JPEG file
What it means
The next_marker() function in wrjpgcom 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. This is the same logic as rdjpgcom's next_marker, applied when writing comments. The function still continues processing.
Source
Thrown at TMessagesProj/jni/mozjpeg/wrjpgcom.c:200
{
int c;
int discarded_bytes = 0;
/* Find 0xFF byte; count and skip any non-FFs. */
c = read_1_byte();
while (c != 0xFF) {
discarded_bytes++;
c = read_1_byte();
}
/* Get marker code byte, swallowing any duplicate FF bytes. Extra FFs
* are legal as pad bytes, so don't count them in discarded_bytes.
*/
do {
c = read_1_byte();
} while (c == 0xFF);
if (discarded_bytes != 0) {
fprintf(stderr, "Warning: garbage data found in JPEG file\n");
}
return c;
}
/*
* Read the initial marker, which should be SOI.
* For a JFIF file, the first two bytes of the file should be literally
* 0xFF M_SOI. To be more general, we could use next_marker, but if the
* input file weren't actually JPEG at all, next_marker might read the whole
* file and then return a misleading error message...
*/
static int
first_marker(void)
{
int c1, c2;View on GitHub (pinned to 45ab8f4308)
Solutions
- Re-encode the JPEG file to normalize the stream: jpegtran -copy none corrupt.jpg > clean.jpg.
- Obtain the file from a trusted source to eliminate corruption.
- Inspect the file with a JPEG analysis tool to identify the garbage region.
- If the file still works correctly after wrjpgcom processing, suppress stderr in automated pipelines.
Example fix
# Normalize the JPEG stream before adding comments jpegtran -copy none input.jpg > cleaned.jpg wrjpgcom -c "My comment" cleaned.jpg > output.jpg
Defensive patterns
Strategy: validation
Validate before calling
# Validate JPEG stream integrity before writing comments if ! jpegtran -copy none "$input" > /dev/null 2>&1; then echo "Warning: $input has structural issues" >&2 fi wrjpgcom -c "comment" "$input" > output.jpg
Prevention
- Pre-process JPEG files through jpegtran to normalize the stream before wrjpgcom.
- Validate JPEG files with a decoder before passing them to wrjpgcom.
- Redirect stderr in automated pipelines if the warning is non-fatal and the output is correct.
When it happens
Trigger: Feeding a corrupted or non-standard JPEG file to wrjpgcom; a JPEG file with stray bytes between marker segments; a file with embedded non-JPEG data that the parser must skip over; a file that has been improperly edited or concatenated.
Common situations: Processing JPEG files from untrusted sources; files with APP markers containing malformed data; JPEG files that were edited with non-compliant tools; files recovered from corrupted storage; files with embedded thumbnails that have incorrect segment lengths.
Related errors
- Warning: garbage data found in JPEG file
- %s: sorry, arithmetic coding not supported
- %s: missing argument for dct
- %s: invalid argument for dct
- %s: missing argument for dc-scan-opt
AI-assisted analysis of DrKLO/Telegram@45ab8f4308 (2026-08-14).
Data as JSON: /api/errors/4e5f035fccf098c0.
Report an issue: GitHub.