@@ -21,22 +21,27 @@ final class ByteBufArraySanitizer {
2121
2222 static byte baload (byte [] array , int index ) {
2323 if (array [0 ] == PATTERN_B1 ) {
24- checkIndexSlow (array , index );
24+ array = checkIndexSlow (array , index );
2525 }
2626 return array [index ];
2727 }
2828
2929 static void bastore (byte [] array , int index , byte value ) {
3030 if (array [0 ] == PATTERN_B1 ) {
31- checkIndexSlow (array , index );
31+ array = checkIndexSlow (array , index );
3232 }
3333 array [index ] = value ;
3434 }
3535
36- private static void checkIndexSlow (byte [] array , int index ) {
36+ private static byte [] checkIndexSlow (byte [] array , int index ) {
3737 Slot slot = findSlot (array );
38- if (slot != null && (index < slot .start || index >= slot .end )) {
39- Jazzer .reportFindingFromHook (new FuzzerSecurityIssueCritical ("Out-of-bounds array access" ));
38+ if (slot != null ) {
39+ if (index < slot .start || index >= slot .end ) {
40+ Jazzer .reportFindingFromHook (new FuzzerSecurityIssueCritical ("Out-of-bounds array access" ));
41+ }
42+ return slot .backing ;
43+ } else {
44+ return array ;
4045 }
4146 }
4247
@@ -85,33 +90,33 @@ static byte[] byteBufArray(ByteBuf buf) {
8590
8691 static byte [] arraysCopyOf (byte [] array , int newLength ) {
8792 if (array .length > 0 && array [0 ] == PATTERN_B1 ) {
88- checkRangeSlow (array , 0 , newLength );
93+ array = checkRangeSlow (array , 0 , newLength );
8994 }
9095 return Arrays .copyOf (array , newLength );
9196 }
9297
9398 static byte [] arraysCopyOfRange (byte [] array , int from , int to ) {
9499 if (array .length > 0 && array [0 ] == PATTERN_B1 ) {
95- checkRangeSlow (array , from , to - from );
100+ array = checkRangeSlow (array , from , to - from );
96101 }
97102 return Arrays .copyOfRange (array , from , to );
98103 }
99104
100105 static void systemArraycopy (Object src , int srcPos , Object dest , int destPos , int length ) {
101106 if (length != 0 ) {
102107 if (src instanceof byte [] s && s [0 ] == PATTERN_B1 ) {
103- checkRangeSlow (s , srcPos , length );
108+ src = checkRangeSlow (s , srcPos , length );
104109 }
105110 if (dest instanceof byte [] d && d [0 ] == PATTERN_B1 ) {
106- checkRangeSlow (d , destPos , length );
111+ dest = checkRangeSlow (d , destPos , length );
107112 }
108113 }
109114 System .arraycopy (src , srcPos , dest , destPos , length );
110115 }
111116
112- private static void checkRangeSlow (byte [] array , int pos , int len ) {
117+ private static byte [] checkRangeSlow (byte [] array , int pos , int len ) {
113118 if (len <= 0 ) {
114- return ;
119+ return array ;
115120 }
116121 Slot slot = findSlot (array );
117122 if (slot != null ) {
@@ -122,6 +127,9 @@ private static void checkRangeSlow(byte[] array, int pos, int len) {
122127 if (pos < start || hi > end ) {
123128 Jazzer .reportFindingFromHook (new FuzzerSecurityIssueCritical ("Out-of-bounds array access" ));
124129 }
130+ return slot .backing ;
131+ } else {
132+ return array ;
125133 }
126134 }
127135
0 commit comments