@@ -1307,7 +1307,15 @@ private static BooleanConstant fixBooleanConstant(IntConstant arg) {
1307
1307
* type constraints (these might be multiple valid possibilities)
1308
1308
*/
1309
1309
private void handleKnownDexArrayTypes (Body b , Jimple jimple , MultiMap <Local , Type > typeConstraints ) {
1310
-
1310
+ Set <Local > localsSingleDefinitions = new HashSet <>(b .getLocals ());
1311
+ for (Unit u : b .getUnits ()) {
1312
+ if (u instanceof DefinitionStmt ) {
1313
+ Value l = ((DefinitionStmt ) u ).getLeftOp ();
1314
+ if (l instanceof Local ) {
1315
+ localsSingleDefinitions .remove (l );
1316
+ }
1317
+ }
1318
+ }
1311
1319
UnitPatchingChain units = jBody .getUnits ();
1312
1320
Unit u = units .getFirst ();
1313
1321
while (u != null ) {
@@ -1321,7 +1329,17 @@ private void handleKnownDexArrayTypes(Body b, Jimple jimple, MultiMap<Local, Typ
1321
1329
Type definiteType = dexplerTypeTag .getDefiniteType ();
1322
1330
if (definiteType != null ) {
1323
1331
Local prev = (Local ) assign .getLeftOp ();
1324
- prev .setType (definiteType );
1332
+ if (!(definiteType instanceof PrimType ) || localsSingleDefinitions .contains (prev )) {
1333
+ prev .setType (definiteType );
1334
+ } else {
1335
+ //Since there are multiple definitions, e.g. for a byte retrieved from a byte[],
1336
+ //there could be another non-distinct definition which uses the same variable as an int.
1337
+ PrimType [] wider = DexType .getWiderTypes ((PrimType ) definiteType );
1338
+ if (wider .length == 1 ) {
1339
+ prev .setType (wider [0 ]);
1340
+ }
1341
+ }
1342
+
1325
1343
ArrayType tp = ArrayType .v (definiteType , 1 );
1326
1344
1327
1345
ArrayRef array = (ArrayRef ) rop ;
0 commit comments