MNT-16381 Transformers must validate the content stream mimetype

- Tika has problems identifying eps - it guesses ps, so allow this through.
   - Fix lost line in DifferrentMimeTypeTest

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@128176 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-06-16 15:23:07 +00:00
parent 60a8b718bc
commit bf346dba70
2 changed files with 10 additions and 4 deletions

View File

@@ -36,7 +36,8 @@ import java.util.concurrent.TimeoutException;
import org.alfresco.api.AlfrescoPublicApi;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.content.AbstractStreamAwareProxy;
import org.alfresco.repo.content.AbstractStreamAwareProxy;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.StreamAwareContentReaderProxy;
import org.alfresco.repo.content.StreamAwareContentWriterProxy;
import org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter;
@@ -252,7 +253,7 @@ public abstract class AbstractContentTransformer2 extends AbstractContentTransfo
// MNT-16381: check the mimetype of the file supplied by the user
// matches the sourceMimetype of the reader. Intermediate files are
// not checked.
strictMimeTypeCheck(reader, options);
strictMimeTypeCheck(reader, options, sourceMimetype);
// Check the transformability
checkTransformable(reader, writer, options);
@@ -438,13 +439,17 @@ public abstract class AbstractContentTransformer2 extends AbstractContentTransfo
}
}
private void strictMimeTypeCheck(ContentReader reader, TransformationOptions options)
private void strictMimeTypeCheck(ContentReader reader, TransformationOptions options, String sourceMimetype)
throws UnsupportedTransformationException
{
if (strictMimeTypeCheck && depth.get() == 1)
{
String differentType = getMimetypeService().getMimetypeIfNotMatches(reader.getReader());
if (differentType != null)
if (differentType != null &&
// Known problematic mimetypes for Tika to identify
!(MimetypeMap.MIMETYPE_APPLICATION_EPS.equals(sourceMimetype) &&
MimetypeMap.MIMETYPE_APPLICATION_PS.equals(differentType))
)
{
String fileName = transformerDebug.getFileName(options, true, 0);
String readerSourceMimetype = reader.getMimetype();

View File

@@ -181,6 +181,7 @@ public class DifferrentMimeTypeTest extends TestCase
}
// Try to transform file with accurate MIME type
contentReader = contentReader.getReader();
contentReader.setMimetype(actualSourceMimetype);
actualTransformer.transform(contentReader, outputWriter, options);
}