From 7296e0e6ba8bcd343fb3cdb78c8590fd0864d469 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Sat, 5 Jan 2019 19:17:37 +0100 Subject: [PATCH] Avoid crash with gzipped file In computing the length of the extension, the code does not account for the prefix "unzipped_", which is added when the zipped filename does not have one of the extensions "gz", "z", "Z", or "svgz", and thus the used index is out of bounds. See also this thread: https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg207360.html --- src/insets/InsetGraphics.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 15c87e4e5e..8c39910675 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -586,8 +586,14 @@ copyToDirIfNeeded(DocFileName const & file, string const & dir) // extension removed, because base.eps and base.eps.gz may // have different content but would get the same mangled // name in this case. + // Also take into account that if the name of the zipped file + // has no zip extension then the name of the unzipped one is + // prefixed by "unzipped_". string const base = removeExtension(file.unzippedFileName()); - string::size_type const ext_len = file_in.length() - base.length(); + string::size_type const prefix_len = + prefixIs(onlyFileName(base), "unzipped_") ? 9 : 0; + string::size_type const ext_len = + file_in.length() + prefix_len - base.length(); mangled[mangled.length() - ext_len] = '.'; } FileName const file_out(makeAbsPath(mangled, dir)); -- 2.39.5