@@ -167,36 +167,20 @@ public void runGhostScriptTestForAllPages() throws IOException, InterruptedExcep
167
167
168
168
@ Test
169
169
public void dSaferParamInGhostScriptHelperTest () throws IOException , InterruptedException {
170
- String cmpPdf = sourceFolder + "maliciousPsInvokingCalcExe.ps" ;
171
- String maliciousPsInvokingCalcExe = destinationFolder + "maliciousPsInvokingCalcExe.png" ;
172
- int majorVersion = 0 ;
173
- int minorVersion = 0 ;
174
- boolean isWindows = identifyOsType ().toLowerCase ().contains ("win" );
175
- if (isWindows ) {
176
- String gsExec = SystemUtil .getPropertyOrEnvironmentVariable (GhostscriptHelper .GHOSTSCRIPT_ENVIRONMENT_VARIABLE );
177
- if (gsExec == null ) {
178
- gsExec = SystemUtil .getPropertyOrEnvironmentVariable (GhostscriptHelper .GHOSTSCRIPT_ENVIRONMENT_VARIABLE_LEGACY );
179
- }
180
- String [] pathParts = gsExec .split ("\\ d\\ .\\ d\\ d" );
181
- for (int i = 0 ; i < pathParts .length ; i ++) {
182
- gsExec = gsExec .replace (pathParts [i ], "" );
183
- }
184
- String [] version = gsExec .split ("\\ ." );
185
- majorVersion = Integer .parseInt (version [0 ]);
186
- minorVersion = Integer .parseInt (version [1 ]);
187
- }
170
+ String input = sourceFolder + "unsafePostScript.ps" ;
171
+ String outputName = "unsafePostScript.png" ;
172
+ String maliciousResult1 = destinationFolder + "output1.txt" ;
173
+ String maliciousResult2 = destinationFolder + "output2.txt" ;
188
174
try {
189
175
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
190
- ghostscriptHelper .runGhostScriptImageGeneration (cmpPdf , destinationFolder , "maliciousPsInvokingCalcExe.png" );
191
- if (isWindows ) {
192
- Assert .assertTrue ((majorVersion > 9 || (majorVersion == 9 && minorVersion >= 50 )));
193
- }
176
+ ghostscriptHelper .runGhostScriptImageGeneration (input , destinationFolder , outputName );
194
177
} catch (GhostscriptHelper .GhostscriptExecutionException e ) {
195
- if ( isWindows ) {
196
- Assert . assertTrue (( majorVersion < 9 || ( majorVersion == 9 && minorVersion < 50 )));
197
- }
178
+ System . out . println ( "Error code was returned on processing of malicious script with -dSAFER option enabled. "
179
+ + "This is expected for some environments and ghostscript versions. "
180
+ + "We assert only the absence of malicious script result (created file). \n " );
198
181
}
199
- Assert .assertFalse (FileUtil .fileExists (maliciousPsInvokingCalcExe ));
182
+ Assert .assertFalse (FileUtil .fileExists (maliciousResult1 ));
183
+ Assert .assertFalse (FileUtil .fileExists (maliciousResult2 ));
200
184
}
201
185
202
186
@ Test
@@ -214,15 +198,4 @@ public void ghostScriptImageGenerationTest() throws IOException, InterruptedExce
214
198
ImageMagickHelper imageMagickHelper = new ImageMagickHelper ();
215
199
Assert .assertTrue (imageMagickHelper .runImageMagickImageCompare (resultantImage , cmpResultantImage , diff ));
216
200
}
217
-
218
- /**
219
- * Identifies type of current OS and return it (win, linux).
220
- *
221
- * @return type of current os as {@link java.lang.String}
222
- */
223
- private static String identifyOsType () {
224
- String os = System .getProperty ("os.name" ) == null
225
- ? System .getProperty ("OS" ) : System .getProperty ("os.name" );
226
- return os .toLowerCase ();
227
- }
228
201
}
0 commit comments