@@ -94,9 +94,20 @@ final class TikaImpl {
94
94
private static final AutoDetectParser PARSER_INSTANCE = new AutoDetectParser (PARSERS );
95
95
96
96
/** singleton tika instance */
97
- private static final Tika TIKA_INSTANCE = new Tika (PARSER_INSTANCE .getDetector (), PARSER_INSTANCE );
97
+ private static final Tika TIKA_INSTANCE = getTikaInstance ();
98
+
99
+ private static Tika getTikaInstance () {
100
+ SpecialPermission .check ();
101
+ try {
102
+ return AccessController .doPrivileged ((PrivilegedExceptionAction <Tika >)
103
+ () -> new Tika (PARSER_INSTANCE .getDetector (), PARSER_INSTANCE ));
104
+ } catch (PrivilegedActionException e ) {
105
+ throw new RuntimeException (e .getCause ());
106
+ }
107
+ }
98
108
99
109
/**
110
+ *
100
111
* parses with tika, throwing any exception hit while parsing the document
101
112
*/
102
113
static String parse (final byte content [], final Metadata metadata , final int limit ) throws TikaException , IOException {
@@ -122,7 +133,7 @@ static String parse(final byte content[], final Metadata metadata, final int lim
122
133
// apply additional containment for parsers, this is intersected with the current permissions
123
134
// its hairy, but worth it so we don't have some XML flaw reading random crap from the FS
124
135
private static final AccessControlContext RESTRICTED_CONTEXT = new AccessControlContext (
125
- new ProtectionDomain [] {
136
+ new ProtectionDomain []{
126
137
new ProtectionDomain (null , getRestrictedPermissions ())
127
138
}
128
139
);
0 commit comments