postgres-nio icon indicating copy to clipboard operation
postgres-nio copied to clipboard

Runtime crush at PostgresNumeric.init

Open sidepelican opened this issue 4 years ago • 0 comments

Describe the bug

PostgresNumeric cannot decode large number (like 1234567890123) and it causes runtime crash.

To Reproduce

  1. call this line
PostgresNumeric(string: "1234567890123")
  1. crash!

Expected behavior

Can call initializer without crash.

Environment

  • Vapor Framework version: 4.48.8
  • postgres-nio: 1.6.2

Additional context

https://github.com/vapor/postgres-nio/blob/046d3ba1a40c5d2e2457177f4311b0b9c97f8945/Sources/PostgresNIO/Data/PostgresData%2BNumeric.swift#L270

this function does not work correctly and return values over maxSize.

let uuu = "1234567890123"
print(uuu.reverseChunked(by: 4)) // ["1", "2345", "67890", "123"]

then here, Int16(67890)! causes crash.

https://github.com/vapor/postgres-nio/blob/046d3ba1a40c5d2e2457177f4311b0b9c97f8945/Sources/PostgresNIO/Data/PostgresData%2BNumeric.swift#L91-L95

sidepelican avatar Oct 11 '21 09:10 sidepelican