-
Notifications
You must be signed in to change notification settings - Fork 193
Model Arrays.copyOf for non-functional arrays for soundness
#191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jjppp
merged 8 commits into
pascal-lab:master
from
auroraberry:fix-arrays-copy-of-model
Sep 12, 2025
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ff3fb8c
Improve Arrays.copyOf handling and add corresponding testcase
auroraberry e5717bd
Address review comments
auroraberry 0bda0e8
capitalize zeroLengthArrayDesc
auroraberry 48b984a
Address review comments
auroraberry 86ef02d
Refactor
jjppp 39da71e
Ignore `Arrays.copyOf()` for PTA Solver to address precision degradation
jjppp 9749d84
Modified the test file to use PTAAssert instead of expected-file
auroraberry deba7a9
Merge branch 'fix-arrays-copy-of-model' of https://github.com/aurorab…
auroraberry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/pascal/taie/analysis/pta/plugin/natives/ArrayCopyOfModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Tai-e: A Static Analysis Framework for Java | ||
| * | ||
| * Copyright (C) 2022 Tian Tan <tiantan@nju.edu.cn> | ||
| * Copyright (C) 2022 Yue Li <yueli@nju.edu.cn> | ||
| * | ||
| * This file is part of Tai-e. | ||
| * | ||
| * Tai-e is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License | ||
| * as published by the Free Software Foundation, either version 3 | ||
| * of the License, or (at your option) any later version. | ||
| * | ||
| * Tai-e is distributed in the hope that it will be useful,but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General | ||
| * Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with Tai-e. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package pascal.taie.analysis.pta.plugin.natives; | ||
|
|
||
| import pascal.taie.analysis.pta.core.cs.context.Context; | ||
| import pascal.taie.analysis.pta.core.cs.element.CSObj; | ||
| import pascal.taie.analysis.pta.core.cs.element.Pointer; | ||
| import pascal.taie.analysis.pta.core.heap.AbstractHeapModel; | ||
| import pascal.taie.analysis.pta.core.heap.Descriptor; | ||
| import pascal.taie.analysis.pta.core.heap.MockObj; | ||
| import pascal.taie.analysis.pta.core.solver.Solver; | ||
| import pascal.taie.analysis.pta.plugin.util.AnalysisModelPlugin; | ||
| import pascal.taie.analysis.pta.plugin.util.InvokeHandler; | ||
| import pascal.taie.analysis.pta.pts.PointsToSet; | ||
| import pascal.taie.ir.exp.Var; | ||
| import pascal.taie.ir.stmt.Invoke; | ||
| import pascal.taie.util.collection.Sets; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| public class ArrayCopyOfModel extends AnalysisModelPlugin { | ||
|
|
||
| private static final Descriptor COPYOF_ARRAY_DESC = () -> "ArrayGeneratedByCopyOfModel"; | ||
|
|
||
| ArrayCopyOfModel(Solver solver) { | ||
| super(solver); | ||
| } | ||
|
|
||
| @InvokeHandler(signature = "<java.util.Arrays: java.lang.Object[] copyOf(java.lang.Object[],int)>", argIndexes = {0}) | ||
| public void arraysCopyOf(Context context, Invoke invoke, PointsToSet from) { | ||
| Var result = invoke.getResult(); | ||
| if(result != null){ | ||
| Pointer to = solver.getCSManager().getCSVar(context, result); | ||
| Set<CSObj> toObjs = Sets.newHybridSet(); | ||
| from.getObjects().forEach(csObj -> { | ||
| // handle the argument0's obj is zero-length-array obj | ||
| if(csObj.getObject() instanceof MockObj mockObj | ||
| && mockObj.getDescriptor().equals(AbstractHeapModel.ZERO_LENGTH_ARRAY_DESC)){ | ||
jjppp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| toObjs.add(solver.getCSManager().getCSObj(context, | ||
| heapModel.getMockObj(COPYOF_ARRAY_DESC, invoke, mockObj.getType()))); | ||
| } | ||
| else { | ||
| toObjs.add(csObj); | ||
| } | ||
| }); | ||
| toObjs.forEach(csObj -> solver.addPointsTo(to, csObj)); | ||
jjppp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/test/resources/pta/taint/ZeroLengthArrayWithArraysCopyOf-pta-expected.txt
jjppp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Detected 1 taint flow(s): | ||
| TaintFlow{<ZeroLengthArrayWithArraysCopyOf: void testZeroLengthArrayPath()>[10@L12] temp$8 = invokestatic ZeroLengthArrayWithArraysCopyOf.getSourceData()/result -> <ZeroLengthArrayWithArraysCopyOf: void testZeroLengthArrayPath()>[15@L13] invokestatic ZeroLengthArrayWithArraysCopyOf.sink(temp$13)/0} |
24 changes: 24 additions & 0 deletions
24
src/test/resources/pta/taint/ZeroLengthArrayWithArraysCopyOf.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import java.util.Arrays; | ||
|
|
||
| public class ZeroLengthArrayWithArraysCopyOf{ | ||
|
|
||
| public static void main(String[] args) { | ||
| testZeroLengthArrayPath(); | ||
| } | ||
|
|
||
| public static void testZeroLengthArrayPath() { | ||
jjppp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String[] original = new String[0]; | ||
| String[] copy = Arrays.copyOf(original, original.length + 1); | ||
| copy[copy.length - 1] = getSourceData(); | ||
| sink(copy[copy.length - 1]); | ||
| } | ||
|
|
||
| public static String getSourceData() { | ||
| return "source_data"; | ||
| } | ||
|
|
||
| public static void sink(String data) { | ||
| System.out.println("Sink: " + data); | ||
| } | ||
|
|
||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/test/resources/pta/taint/taint-config-zero-length-array-with-arrays-copy-of.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| sources: | ||
| - { kind: call, method: "<ZeroLengthArrayWithArraysCopyOf: java.lang.String getSourceData()>", index: result } | ||
|
|
||
| sinks: | ||
| - { method: "<ZeroLengthArrayWithArraysCopyOf: void sink(java.lang.String)>", index: 0 } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.