MNT-15359,MNT-14437,ALF-21479,MNT-16609: Remove dependency on filename for office transformations

<< Root cause for these 4 issues was a fix made in 4.2.4 MNT-11279. That fix was trying to
      use the file name field value in a document when transformed to PDF. In addition to the
      3  problems found, using file names supplied by users is a potential security issue.
      We have not found a way to exploit the use of the original file name, but that should
      not stop us from closing off the possibility. Fix is being merged to the dot N branches
      of 5.2, 5.1, 5.0 and 4.2 so the fix will be in the next service pack for each branch.
      The original MNT-16609 fix is also being reverted as the original code included the source
      extension in the temporary file name. >>> 
      Reverse merged 5.2.N (5.2.1)
         129407 skopf: MNT-16609 - Alfresco OOTB install doesn't show preview for .EML files on Windows
         94626 adavis: Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
            89429: ACE-2649: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud)
               89386: Merged DEV to 4.2-BUG-FIX (4.2.4)
                  85587: MNT-11279: Docx Preview: FileName in the document header not previewing correctly
                     - Keep original name during convertion.
                     - Add unit test


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@133715 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-12-15 11:14:17 +00:00
parent d52ae9ea3f
commit 877fdb05e8
3 changed files with 31 additions and 93 deletions

View File

@@ -1,28 +1,28 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.repo.content.transform;
import java.io.BufferedOutputStream;
@@ -34,7 +34,6 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Date;
import com.sun.star.task.ErrorCodeIOException;
import net.sf.jooreports.converter.DocumentFamily;
@@ -50,7 +49,6 @@ import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.TransformationOptions;
import org.alfresco.util.GUID;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log;
import org.apache.pdfbox.exceptions.COSVisitorException;
@@ -345,27 +343,13 @@ public abstract class OOoContentTransformerHelper extends ContentTransformerHelp
" writer: " + writer);
}
// MNT-11279 fix. Because of the creating temp files for transformations the document's header with file name field
// could be changed to temporary file's name.
// Get the original file name which was on upload.
String origFileName = getOriginalFileName(options);
if (origFileName == null)
{
origFileName = "TemporaryFile-" + GUID.generate() + "." + sourceExtension;
}
// Create a temp folder and put source and target files into it. (i.e. tempFromFile and tempToFile will be placed
// into such folder)
File tempSubfolder = new File(TempFileProvider.getTempDir() + File.separator +
origFileName + "-" + getTempFilePrefix() + "-"
+ getTempFilePrefix() + "-" + new Date().getTime());
tempSubfolder.mkdir();
// create temporary files to convert from and to
// The source file should have the name which was on upload
File tempFromFile = new File(tempSubfolder, origFileName );
File tempFromFile = TempFileProvider.createTempFile(
getTempFilePrefix()+"-source-",
"." + sourceExtension);
File tempToFile = TempFileProvider.createTempFile(
origFileName + "-" + getTempFilePrefix()+"-target-",
"." + targetExtension, tempSubfolder);
getTempFilePrefix()+"-target-",
"." + targetExtension);
// There is a bug (reported in ALF-219) whereby JooConverter (the Alfresco Community Edition's 3rd party
// OpenOffice connector library) struggles to handle zero-size files being transformed to pdf.
@@ -438,12 +422,7 @@ public abstract class OOoContentTransformerHelper extends ContentTransformerHelp
getLogger().debug("transformation successful");
}
}
private String getOriginalFileName(TransformationOptions options)
{
return transformerDebug == null ? null : transformerDebug.getFileName(options, true, -1);
}
private boolean temporaryMsFile(TransformationOptions options)
{
String fileName = transformerDebug == null ? null : transformerDebug.getFileName(options, true, -1);