Usage of multibyte character encodings (e.g. cyrillic) leads to mistakes:

Warning: htmlspecialchars() [function.htmlspecialchars]: Invalid multibyte sequence in argument in check_plain()
...
PDOException: in drupal_write_record()

One can solve the problem replacing substr by mb_substr or better (thanks to Viktor) by drupal_substring.

Replace

<?php
 
// Ensure the generated title isn't too long.
 
$node->title = substr($node->title, 0, 255);
?>

by

<?php
 
// Ensure the generated title isn't too long.
 
$node->title = drupal_substr($node->title, 0, 255);
?>
Files: 
CommentFileSizeAuthor
multibyte_substr.patch604 bytesvaplas