]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commit
check for invalid utf-8, and toss it back to avoid crashes
authorJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Nov 2008 22:39:42 +0000 (17:39 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Wed, 12 Nov 2008 22:39:42 +0000 (17:39 -0500)
commit57b5838b6a1015f7c543ebdb6d2b383d8b44756d
treeefbba2c62f52b9011edc9119b752807d0a3dbbe4
parentf8dd704a707149cf1fe02974a7f56b558df553c8
check for invalid utf-8, and toss it back to avoid crashes

Since ikiwiki uses open :utf8, perl assumes that files contain valid utf-8.
If it turns out to be malformed it may later crash while processing strings
read from them, with 'Malformed UTF-8 character (fatal)'.

As at least a quick fix, use utf8::valid as soon as data is read, and if
it's not valid, call encode_utf8 on the string, thus clearing the utf-8
flag. This may cause follow-on encoding problems, but will avoid this
crash, and the input file was broken anyway, so GIGO is a reasonable
response. (I looked at calling decode_utf8 after, but it seemed to cause
more trouble than it was worth. BTW, use open ':encoding(utf8)' avaoids
this problem, but the corrupted data later causes Storable to crash when
writing the index.)

This is a quick fix, clearly imperfect:
- It might be better to explicitly call decode_utf8 when reading files,
  rather than using the IO layer.
- Data read other than by readfile() can still sneak in bad utf-8. While
  ikiwiki does very little file input not using it, stdin for the CGI
  would be one way.
(cherry picked from commit 716560b7f15b6e15b246c39c11eb8181d91c8662)

Conflicts:

debian/changelog
IkiWiki.pm
debian/changelog
doc/security.mdwn