 
     /// Replaces with a given set of bytes a given range within the contents of the data object.
     open func replaceBytes(in range: NSRange, withBytes replacementBytes: UnsafeRawPointer?, length replacementLength: Int) {
-        let bytePtr = replacementBytes?.bindMemory(to: UInt8.self, capacity: replacementLength)
-        CFDataReplaceBytes(_cfMutableObject, CFRangeMake(range.location, range.length), bytePtr, replacementLength)
+        precondition(range.location + range.length <= self.length)
+        if funnelsAreAbstract {
+            let delta = replacementLength - range.length
+            if delta != 0 {
+                let originalLength = self.length
+                self.length += delta
+                
+                if delta > 0 {
+                    UnsafeRawBufferPointer(start: mutableBytes.advanced(by: range.location), count: originalLength).copyBytes(to: UnsafeMutableRawBufferPointer(start: mutableBytes.advanced(by: range.location + range.length), count: originalLength))
+                }
+            }
+            UnsafeRawBufferPointer(start: replacementBytes, count: replacementLength).copyBytes(to: UnsafeMutableRawBufferPointer(start: mutableBytes.advanced(by: range.location), count: replacementLength))
+        } else {
+            let bytePtr = replacementBytes?.bindMemory(to: UInt8.self, capacity: replacementLength)
+            CFDataReplaceBytes(_cfMutableObject, CFRangeMake(range.location, range.length), bytePtr, replacementLength)
+        }
     }
 }
 

internal func _CFSwiftDataReplaceBytes(_ data: CFTypeRef, _ range: CFRange, _ buffer: UnsafeRawPointer?, _ count: CFIndex) {
    (data as! NSMutableData).replaceBytes(in: NSMakeRange(range.location, range.length), withBytes: buffer, length: count)
}


    /// The number of bytes contained by the data object.
    open var length: Int {
        requireFunnelOverridden()
        return CFDataGetLength(_cfObject)
    }

    /// A pointer to the data object's contents.
    open var bytes: UnsafeRawPointer {
        requireFunnelOverridden()
        guard let bytePtr = CFDataGetBytePtr(_cfObject) else {
            //This could occure on empty data being encoded.
            //TODO: switch with nil when signature is fixed
