File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/*
22 * Transcoding support for CUPS.
33 *
4- * Copyright © 2020-2024 by OpenPrinting.
5- * Copyright 2007-2014 by Apple Inc.
6- * Copyright 1997-2007 by Easy Software Products.
4+ * Copyright © 2020-2025 by OpenPrinting.
5+ * Copyright © 2007-2014 by Apple Inc.
6+ * Copyright © 1997-2007 by Easy Software Products.
77 *
8- * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
9- */
10-
11- /*
12- * Include necessary headers...
8+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
9+ * information.
1310 */
1411
1512#include "cups-private.h"
@@ -246,20 +243,26 @@ cupsUTF8ToCharset(
246243 {
247244 ch = * src ++ ;
248245
249- if ((ch & 0xe0 ) == 0xc0 )
246+ if ((ch & 0xe0 ) == 0xc0 && ( * src & 0xc0 ) == 0x80 )
250247 {
248+ // 2-byte UTF-8
251249 ch = ((ch & 0x1f ) << 6 ) | (* src ++ & 0x3f );
252250
253251 if (ch < maxch )
254252 * destptr ++ = (char )ch ;
255253 else
256254 * destptr ++ = '?' ;
257255 }
258- else if ((ch & 0xf0 ) == 0xe0 ||
259- (ch & 0xf8 ) == 0xf0 )
256+ else if ((ch & 0xf0 ) == 0xe0 || (ch & 0xf8 ) == 0xf0 )
257+ {
258+ // 3-byte or 4-byte UTF-8
260259 * destptr ++ = '?' ;
260+ }
261261 else if (!(ch & 0x80 ))
262+ {
263+ // ASCII
262264 * destptr ++ = (char )ch ;
265+ }
263266 }
264267
265268 * destptr = '\0' ;
You can’t perform that action at this time.
0 commit comments