@@ -3677,6 +3677,50 @@ class TestData : TestDataSuper {
3677
3677
let h3 = d3. hashValue
3678
3678
expectEqual ( h1, h3)
3679
3679
}
3680
+
3681
+ func test_validateMutation_slice_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
3682
+ var data = Data ( bytes: [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) [ 4 ..< 6 ]
3683
+ data. withUnsafeMutableBytes { ( ptr: UnsafeMutablePointer < UInt8 > ) in
3684
+ ptr. advanced ( by: 1 ) . pointee = 0xFF
3685
+ }
3686
+ expectEqual ( data, Data ( bytes: [ 4 , 0xFF ] ) )
3687
+ }
3688
+
3689
+ func test_validateMutation_slice_immutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
3690
+ var data = Data ( referencing: NSData ( bytes: " hello world " , length: 11 ) ) [ 4 ..< 6 ]
3691
+ data. withUnsafeMutableBytes { ( ptr: UnsafeMutablePointer < UInt8 > ) in
3692
+ ptr. advanced ( by: 1 ) . pointee = 0xFF
3693
+ }
3694
+ expectEqual ( data [ data. startIndex. advanced ( by: 1 ) ] , 0xFF )
3695
+ }
3696
+
3697
+ func test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
3698
+ var base = Data ( referencing: NSData ( bytes: " hello world " , length: 11 ) )
3699
+ base. append ( contentsOf: [ 1 , 2 , 3 , 4 , 5 , 6 ] )
3700
+ var data = base [ 4 ..< 6 ]
3701
+ data. withUnsafeMutableBytes { ( ptr: UnsafeMutablePointer < UInt8 > ) in
3702
+ ptr. advanced ( by: 1 ) . pointee = 0xFF
3703
+ }
3704
+ expectEqual ( data [ data. startIndex. advanced ( by: 1 ) ] , 0xFF )
3705
+ }
3706
+
3707
+ func test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
3708
+ var data = Data ( referencing: AllOnesImmutableData ( length: 10 ) ) [ 4 ..< 6 ]
3709
+ data. withUnsafeMutableBytes { ( ptr: UnsafeMutablePointer < UInt8 > ) in
3710
+ ptr. advanced ( by: 1 ) . pointee = 0xFF
3711
+ }
3712
+ expectEqual ( data [ data. startIndex. advanced ( by: 1 ) ] , 0xFF )
3713
+ }
3714
+
3715
+ func test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound( ) {
3716
+ var base = Data ( referencing: AllOnesData ( length: 1 ) )
3717
+ base. count = 10
3718
+ var data = base [ 4 ..< 6 ]
3719
+ data. withUnsafeMutableBytes { ( ptr: UnsafeMutablePointer < UInt8 > ) in
3720
+ ptr. advanced ( by: 1 ) . pointee = 0xFF
3721
+ }
3722
+ expectEqual ( data [ data. startIndex. advanced ( by: 1 ) ] , 0xFF )
3723
+ }
3680
3724
}
3681
3725
3682
3726
#if !FOUNDATION_XCTEST
@@ -3988,6 +4032,11 @@ DataTests.test("test_sliceHash") { TestData().test_sliceHash() }
3988
4032
DataTests . test ( " test_slice_resize_growth " ) { TestData ( ) . test_slice_resize_growth ( ) }
3989
4033
DataTests . test ( " test_sliceEnumeration " ) { TestData ( ) . test_sliceEnumeration ( ) }
3990
4034
DataTests . test ( " test_hashEmptyData " ) { TestData ( ) . test_hashEmptyData ( ) }
4035
+ DataTests . test ( " test_validateMutation_slice_withUnsafeMutableBytes_lengthLessThanLowerBound " ) { TestData ( ) . test_validateMutation_slice_withUnsafeMutableBytes_lengthLessThanLowerBound ( ) }
4036
+ DataTests . test ( " test_validateMutation_slice_immutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound " ) { TestData ( ) . test_validateMutation_slice_immutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound ( ) }
4037
+ DataTests . test ( " test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound " ) { TestData ( ) . test_validateMutation_slice_mutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound ( ) }
4038
+ DataTests . test ( " test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound " ) { TestData ( ) . test_validateMutation_slice_customBacking_withUnsafeMutableBytes_lengthLessThanLowerBound ( ) }
4039
+ DataTests . test ( " test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound " ) { TestData ( ) . test_validateMutation_slice_customMutableBacking_withUnsafeMutableBytes_lengthLessThanLowerBound ( ) }
3991
4040
3992
4041
// XCTest does not have a crash detection, whereas lit does
3993
4042
DataTests . test ( " bounding failure subdata " ) {
0 commit comments