内存不足,无法完成分析

Not enough memory to complete analysis

我遇到了一个与强化扫描相关的非常不寻常的错误。它从昨天晚上开始,我一直在努力解决它,因为它影响了整个团队的工作。我在 Jenkins 控制台中收到以下错误消息。

我试图通过在 Jenkins 管道代码中使用以下参数来增加内存和 java 堆大小来进行故障排除,但这也没有帮助。 fortifyMemory: '-Xmx6G -Xms2400M -Xss48M'.

我尝试使用排除更多文件 sourceExclusions: 'src/main/resources/**/*.*, 但这也不起作用。

我在网上发现也许使用并行处理并将 java 版本类型更改为 64 位 -64 可能会解决问题,但无法在我的 Jenkins 管道中正确配置它,因为没有太多信息可用。

如果有人知道如何在下面的管道代码中传递这两个标志,或者是否有其他解决方案,请告诉我。

stage('Fortify Scan') {
    agent {
        label 'docker-fortify-slave'
    }
    steps {
        unstash 'build'
        fortifyscanjava([
            useExternalDependencyDirectory: false,
            buildVersion: "${TAG_VAL}",
            fortifyCredentialsId: "fortify-credentials",

            fortifyJavaVersion: '1.8',

            sourceDirectory: "${env.WORKSPACE}/dist",
            sourceExclusions: '',
            criticalThreshold: 0,
            fortifyMemory: '-Xmx32G -Xms4800M -Xss196M',
            highThreshold: 0,
            mediumThreshold: 1000,
            lowThreshold: 1000,
            fortifyVersion: '17.20',
            failBuildAfterThresholdPassed: true,
            archiveReports: true,
            uploadScan: false,
            sourceAnalyzerArgs: '',
            onlyNewIssues: true,
            outputFormatHtml: true,
            additionalIssueFilters: 'analysis:!Not an Issue'
        ])
    }
}

Fortify SCA 占用大量内存来扫描大中型应用程序。

在您的示例中的第 13 行附近,删除 "fortifyMemory: '-Xmx1G -Xms600M -Xss24M -mt',".

在第 17 行附近,如果可能,将内存增加到“-Xmx16G”(或任何可能的内存)。基本上,继续在问题上投入更多内存,直到 Fortify 中的 "Not enough memory" warning/error 消失。

还有...

可能发生的事情的解释

Fortify SCA 的“-mt”选项意味着您要启用并行分析模式,该模式旨在通过创建多个从属进程来协助扫描来尝试加速源代码扫描。使用“-mt”,Fortify 会自动为主机上的每个 cpu 核心创建 1 个从属进程,并且由于你的“-Xmx1GB”,Fortify 会为每个进程分配 1GB 内存。因此,您看到的错误可能是因为一个或多个从属 运行 内存不足。

结论

对于这个初始扫描,不要使用并行分析模式。这就是我们在您的示例中删除第 13 行的原因。此外,您在第 17 行再次具有重复的内存配置设置。 成功生成扫描后,尝试拨回内存量,然后尝试使用并行分析模式。 使用并行分析模式时,使用“-Xmx”计算要分配多少内存的公式可能是: ( - 2GB) / <# of cpu 个内核>

也许在您的情况下使用 CloudScan 会更好。

https://www.microfocus.com/documentation/fortify-software-security-center/1820/CloudScan_Guide_18.20.pdf

"The translation phase, which isless processor- and time-intensive, is completed on the build machine. After translation is completed, CloudScan generates a package, which it then movesto a distributed cloud of machines(sensors) forscanning. In addition to freeing up build machines, this process makesit easy to add more resourcesto the cloud and grow the system as needed, without having to interrupt your build process. And, Fortify Software Security Center can direct CloudScan to output FPR files directly to the server."

Fortify 扫描期间可能会出现 System.OutOfMemoryException 错误。

对于 .net 文件,我们使用名为 4gb_patch.exe 的小工具解决了修复在 Fortify 扫描阶段使用的文件 dotnet-translator.exe 的问题。该工具修补 x86 可执行文件以允许它们在 x64 平台上拥有 4 GB 的虚拟内存(而不是 2 GB)。您可以从 https://ntcore.com/?page_id=371.

下载该工具

dotnet-translator.exe 文件可在以下位置找到: C:\Program Files\HPE_Security\Fortify_SCA_and_Apps_xx.xx\Core\private-bin\sca\dotnet-translator.exe

当然,您需要使用您的 Fortify SCA 版本更改 XX.xx。 ;)