Reject CALOAD on non-char arrays in structural verification#522
Conversation
visitCALOAD only checked that the arrayref is an array, never that its component type is char, so Pass3b accepted caload on any array such as int[] or a reference array. Add the char component check that the sibling visitCASTORE already performs.
|
Thank you @rootvector2 ; merged 🚀 Do you see similar issues with other |
|
checked the rest and they're all covered now. the |
|
Thank you for checking @rootvector2 |
|
partially. |
|
@rootvector2 A follow up PR with the missing tests would be great. It will be nice to achieve parity in avoiding regressions. TY! |
|
opened #524 with the missing tests. one parameterized creator covers |
#524) TestArrayAccess05 and TestArrayAccess06 only cover iaload and caload, so the component type checks for the remaining array load/store instructions in InstConstraintVisitor have no negative tests. Add a parameterized TestArrayAccess07Creator that applies a given array access instruction to an array whose component type does not match (castore on an int[], iastore on a char[], and so on) and assert that structural verification rejects each of aaload, aastore, baload, bastore, castore, daload, dastore, faload, fastore, iastore, laload, lastore, saload and sastore. Make TestCreator.getClassName protected so the creator can name the generated class per instruction instead of adding fourteen creator subclasses. Follow-up to #522.
InstConstraintVisitor.visitCALOADonly checks that the arrayref is some array, never that its component type ischar, so Pass3b structural verification acceptscaloadon any array such as anint[]or a reference array likeString[].ExecutionVisitor.visitCALOADthen models the loaded value asint, so a reference read throughcaloadis type confused as an int while the class still verifies. Found by comparingvisitCALOADagainst its store counterpartvisitCASTOREjust below it, which does checkchar.Add the same component-type check that
visitCASTOREuses so the constraint sits next to the other array-access checks in the structural pass.TestArrayAccess06appliescaloadto anint[]and asserts verification rejects it.mvn; that'smvnon the command line by itself.