On Sun, Oct 06, 2013 at 12:09:50PM -0400, Richard Heck wrote: > > I just wanted to call everyone's attention to this bug: > http://www.lyx.org/trac/ticket/8854 > It appears to be a very nasty dataloss bug in 2.1-beta1. What seems > to be happening is that, on save, the LyX file is corrupted in very > weird ways, with random parts of the file being replaced by things > like "mathnorma" or "Plain La"---fragments of things that do make > sense in other contexts. > > A report of what looks like the same bug in 2.0.6 is here: > http://tex.stackexchange.com/questions/134009/lyx-inserts-and-removes-words-randomly > That was on Windows, as well, whereas #8854 is on Ubuntu. Another > difference is that #8854 seems to show up only on export. The > original report was of corruption in the exported 2.0 file, but by > looking in the temporary directory we found that the 2.1 file was > already corrupt. That makes it sound as if the problem has to do > with background export. But the 2.0.6 report seems to concern just > saving the file and not export. > > The reporter has done some excellent work to help us figure this > out, but neither Pavel nor I have been able to reproduce---though > the reporter sees it all the time. It would really, really help if > someone could manage to reproduce this. > > Obviously, it would also help if someone has a good idea what might > cause this.
I can reproduce this bug on several platforms and I am surprised that nobody else can. The problem here is that to_utf8() (and most probably all other conversion routines) is not thread safe, maybe due to the static output buffer in iconv_convert(). This is demonstrated by the attached quick and dirty patch. Without this patch, I get a good export only about once every ten trails. With the patch the exported file is always correct. -- Enrico
diff --git a/src/support/docstring.cpp b/src/support/docstring.cpp index 727e1f5..db4f513 100644 --- a/src/support/docstring.cpp +++ b/src/support/docstring.cpp @@ -107,7 +107,7 @@ docstring const from_utf8(string const & utf8) string const to_utf8(docstring const & ucs4) { - vector<char> const utf8 = ucs4_to_utf8(ucs4.data(), ucs4.size()); + QByteArray utf8 = toqstr(ucs4).toUtf8(); return string(utf8.begin(), utf8.end()); }