Menu

#45 [PATCH] libdjvu: fix strict-aliasing violation in UTF-8 decoding

Unstable_(example)
open
nobody
None
5
3 days ago
3 days ago
oltolm
No

GStringRep::UTF8::getValidUCS4() casts a const char * reference to
an incompatible const unsigned char * reference. UTF8toUCS4()
then updates the pointer through the wrong reference type, violating
C++ aliasing rules.

With GCC 16.2 at -O3 on MSYS2 UCRT64, the optimizer assumes that
source is unchanged. Whitespace in languages.xml is then rejected
during context creation; DjView crashes when it uses the null context.

Use a separate unsigned-char pointer for the decoder, then copy its
advanced value back to source.

Tested on MSYS2 UCRT64 with DjVuLibre 3.5.30 and GCC 16.2:
DjView starts after rebuilding with this change.

1 Attachments

Discussion


Log in to post a comment.