up
Some checks failed
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-12-13 09:37:15 +02:00
parent e00f6365da
commit 6e45066e37
349 changed files with 17160 additions and 1867 deletions

View File

@@ -13,6 +13,10 @@ internal static class JavaJniAnalyzer
{
private const ushort AccNative = 0x0100;
private const int MaxEdges = 2000;
private const int MaxWarnings = 200;
private const int MaxClassesPerSegment = 5000;
// Method references for System.load/loadLibrary and Runtime.load/loadLibrary
private static readonly (string ClassName, string MethodName, string Descriptor, JavaJniReason Reason)[] JniLoadMethods =
[
@@ -38,11 +42,44 @@ internal static class JavaJniAnalyzer
{
cancellationToken.ThrowIfCancellationRequested();
foreach (var kvp in segment.ClassLocations)
var classesScanned = 0;
foreach (var kvp in segment.ClassLocations.OrderBy(static pair => pair.Key, StringComparer.Ordinal))
{
var className = kvp.Key;
var location = kvp.Value;
if (edges.Count >= MaxEdges)
{
if (warnings.Count < MaxWarnings)
{
warnings.Add(new JavaJniWarning(
SourceClass: "*",
SegmentIdentifier: segment.Identifier,
WarningCode: "JNI_EDGE_LIMIT_REACHED",
Message: $"JNI edge limit ({MaxEdges}) reached; output truncated.",
MethodName: string.Empty,
MethodDescriptor: string.Empty));
}
break;
}
if (classesScanned++ >= MaxClassesPerSegment)
{
if (warnings.Count < MaxWarnings)
{
warnings.Add(new JavaJniWarning(
SourceClass: "*",
SegmentIdentifier: segment.Identifier,
WarningCode: "JNI_CLASS_LIMIT_REACHED",
Message: $"JNI class scan limit ({MaxClassesPerSegment}) reached for segment; output truncated.",
MethodName: string.Empty,
MethodDescriptor: string.Empty));
}
break;
}
try
{
using var stream = location.OpenClassStream(cancellationToken);
@@ -55,6 +92,11 @@ internal static class JavaJniAnalyzer
if (method.IsNative)
{
if (edges.Count >= MaxEdges)
{
break;
}
edges.Add(new JavaJniEdge(
SourceClass: className,
SegmentIdentifier: segment.Identifier,
@@ -65,26 +107,44 @@ internal static class JavaJniAnalyzer
MethodDescriptor: method.Descriptor,
InstructionOffset: -1,
Details: "native method declaration"));
if (edges.Count >= MaxEdges)
{
break;
}
}
// Analyze bytecode for System.load/loadLibrary calls
if (method.Code is not null)
{
AnalyzeMethodCode(classFile, method, segment.Identifier, className, edges, warnings);
if (edges.Count >= MaxEdges)
{
break;
}
}
}
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
warnings.Add(new JavaJniWarning(
SourceClass: className,
SegmentIdentifier: segment.Identifier,
WarningCode: "JNI_PARSE_ERROR",
Message: $"Failed to parse class file: {ex.Message}",
MethodName: string.Empty,
MethodDescriptor: string.Empty));
if (warnings.Count < MaxWarnings)
{
warnings.Add(new JavaJniWarning(
SourceClass: className,
SegmentIdentifier: segment.Identifier,
WarningCode: "JNI_PARSE_ERROR",
Message: $"Failed to parse class file: {ex.Message}",
MethodName: string.Empty,
MethodDescriptor: string.Empty));
}
}
}
if (edges.Count >= MaxEdges)
{
break;
}
}
if (edges.Count == 0 && warnings.Count == 0)
@@ -234,6 +294,11 @@ internal static class JavaJniAnalyzer
string className,
List<JavaJniEdge> edges)
{
if (edges.Count >= MaxEdges)
{
return;
}
var methodRef = classFile.ConstantPool.ResolveMethodRef(methodRefIndex);
if (methodRef is null)
{