dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.10.0.1456'
dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.10.0.3710'
dependency 'org.sonarsource.slang:sonar-scala-plugin:1.10.0.3710'
- dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.9.0.229'
+ dependency 'org.sonarsource.api.plugin:sonar-plugin-api:9.10.0.269'
dependency 'org.sonarsource.xml:sonar-xml-plugin:2.5.0.3376'
dependency 'org.sonarsource.iac:sonar-iac-plugin:1.9.2.2279'
dependency 'org.sonarsource.text:sonar-text-plugin:1.1.0.282'
*/
public class ExtractReportStep implements ComputationStep {
+ static final long REPORT_SIZE_THRESHOLD_IN_BYTES = 2_000_000_000;
private static final Logger LOGGER = Loggers.get(ExtractReportStep.class);
private final DbClient dbClient;
File unzippedDir = tempFolder.newDir();
try (DbInputStream reportStream = opt.get();
InputStream zipStream = new BufferedInputStream(reportStream)) {
- ZipUtils.unzip(zipStream, unzippedDir);
+ ZipUtils.unzip(zipStream, unzippedDir, REPORT_SIZE_THRESHOLD_IN_BYTES);
} catch (IOException e) {
throw new IllegalStateException("Fail to extract report " + task.getUuid() + " from database", e);
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
assertThat(logTester.logs(LoggerLevel.DEBUG)).anyMatch(log -> log.matches("Analysis report is \\d+ bytes uncompressed"));
}
+ @Test
+ public void unzip_report_should_fail_if_unzip_size_exceed_threshold() throws Exception {
+ logTester.setLevel(LoggerLevel.DEBUG);
+ URL zipBombFile = getClass().getResource("/org/sonar/ce/task/projectanalysis/step/ExtractReportStepTest/zip-bomb.zip");
+ try (InputStream input = zipBombFile.openStream()) {
+ dbTester.getDbClient().ceTaskInputDao().insert(dbTester.getSession(), TASK_UUID, input);
+ }
+ dbTester.getSession().commit();
+ dbTester.getSession().close();
+
+ assertThatThrownBy(() -> underTest.execute(new TestComputationStepContext()))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("Decompression failed because unzipped size reached threshold: 2000000000 bytes");
+ }
+
private File generateReport() throws IOException {
File zipDir = tempFolder.newDir();
File metadataFile = new File(zipDir, "metadata.pb");