Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Oct 21, 2024
1 parent e9c3f5c commit efc4fa6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Codec/Sources/Codec/DataInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public protocol DataInput {

extension DataInput {
public mutating func read() throws -> UInt8 {
try read(length: 1)[0]
try read(length: 1).first!
}

public mutating func decode() throws -> UInt64 {
public mutating func decodeUInt64() throws -> UInt64 {
// TODO: improve this by use `read(minLength: 8)` to avoid read byte by byte
let res = try IntegerCodec.decode { try self.read() }
guard let res else {
Expand Down
6 changes: 3 additions & 3 deletions Codec/Sources/Codec/JamDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private class DecodeContext: Decoder {
}

fileprivate func decodeData(codingPath: @autoclosure () -> [CodingKey]) throws -> Data {
let length = try input.decode()
let length = try input.decodeUInt64()
// sanity check: length must be less than 4gb
guard length < 0x1_0000_0000 else {
throw DecodingError.dataCorrupted(
Expand All @@ -115,7 +115,7 @@ private class DecodeContext: Decoder {
}

fileprivate func decodeData(codingPath: @autoclosure () -> [CodingKey]) throws -> [UInt8] {
let length = try input.decode()
let length = try input.decodeUInt64()
// sanity check: length must be less than 4gb
guard length < 0x1_0000_0000 else {
throw DecodingError.dataCorrupted(
Expand All @@ -130,7 +130,7 @@ private class DecodeContext: Decoder {
}

fileprivate func decodeArray<T: ArrayWrapper>(_ type: T.Type, key: CodingKey?) throws -> T {
let length = try input.decode()
let length = try input.decodeUInt64()
// sanity check: length can't be unreasonably large
guard length < 0xFFFFFF else {
throw DecodingError.dataCorrupted(
Expand Down

0 comments on commit efc4fa6

Please sign in to comment.