             for _ in 0..<segCount {
                 self.idDelta.append(try data.decode(BEInt16.self))
             }
-            for _ in 0..<segCount {
-                self.idRangeOffset.append(try data.decode(BEUInt16.self))
-            }
+            
+            let ramainSize = Int(self.length) - (record - data.count)
+            guard ramainSize > 0 else { throw FontCollection.Error.InvalidFormat("Invalid cmap format.") }
+            guard data.count >= ramainSize else { throw DataDecodeError.endOfData }
+            
+            self.idRangeOffset = data.popFirst(ramainSize)
         }
         
         subscript(code: UInt32) -> Int {

            self.startCode = []
            self.idDelta = []
            self.idRangeOffset = []
            self.glyphIndexArray = []
            self.endCode.reserveCapacity(segCount)
            self.startCode.reserveCapacity(segCount)
            self.idDelta.reserveCapacity(segCount)
            self.idRangeOffset.reserveCapacity(segCount)
            
            for _ in 0..<segCount {
                self.endCode.append(try data.decode(BEUInt16.self))

        var reservedPad: BEUInt16
        var startCode: [BEUInt16]
        var idDelta: [BEInt16]
        var idRangeOffset: Data
        
        init(from data: inout Data) throws {
            
            let record = data.count
            
            self.format = try data.decode(BEUInt16.self)
            self.length = try data.decode(BEUInt16.self)
            self.language = try data.decode(BEUInt16.self)
