Skip to content

Lenient .csv.read wraps out-of-range integers to the column width and turns F32 overflow into inf #1892

Backlog

Description

@singaraiona

Summary

The default (lenient) .csv.read keeps an out-of-range number as a different value instead of a null: an integer is wrapped to the column's width, the type's minimum is stored as the null sentinel, and a float past the F32 range becomes an infinity.

Repro (dev 2ed4637)

printf 'u,h,i,e\n300,40000,3000000000,1e39\n-1,-32768,-2147483648,3.4e38\n' > wrap.csv
(set t (.csv.read [U8 I16 I32 F32] "wrap.csv"))
(at t 'u)   ; [0x2c 0xff]          300 -> 44, -1 -> 255
(at t 'h)   ; [-25536 -32768]      40000 wraps; -32768 is NULL_I16, kept as the sentinel
(at t 'i)   ; [-1294967296 -2147483648]
(at t 'e)   ; [infe 3.40e+38e]     1e39 -> inf in an F32

An I64 overflow and 1e400 in an F64 already read as nulls; the narrower widths do not. The parse goes through fast_i64 and casts to the column's width (csv_parse_fn, the I16/I32/U8 cases), and F32 casts a finite double to float.

Decision needed

Making these nulls (as I64 and F64 already are) changes what existing reads return, so it is for the owner. {strict: true} (#1888) already refuses each of them with "300" is out of range for a U8.

Activity

  1. singaraiona commented on Nov 28, 2026

    @singaraiona
    CollaboratorAuthor

    The same class for TIMESTAMP, and there it is also undefined behaviour in C: an instant outside the type's range (2000-01-01 ± 292 years: 1707-09-22T00:12:43.145224193 .. 2292-04-10T23:47:16.854775807) is computed as a signed int64 that overflows.

    printf 'v\n9999-01-01T00:00:00\n1600-01-01T00:00:00\n' > ts.csv
    (at (.csv.read [TIMESTAMP] "ts.csv") 'v)
    ; release build (dev 2ed46378d): [1815.03.31D05:56:08.066277376 2184.07.20D23:34:33.709551616]
    ; debug build (UBSan):  src/io/csv.c:713:36: runtime error: signed integer overflow:
    ;                       86400000000000 * 2921575 cannot be represented in type 'long int'

    The overflow is int64_t result = (int64_t)days * NS_PER_DAY + time_ns; in fast_timestamp (src/io/csv.c:713; result -= adj; at 727 can overflow too, with a UTC offset at the ends of the range). The type-inference sampler calls fast_timestamp as well, so (.csv.read "ts.csv") without a schema reaches it. Even on the earliest day of the range (1707-09-22), where the instant fits, days * NS_PER_DAY alone overflows. {strict: true} (#1888) parses timestamps with its own checked arithmetic and refuses these as out of range; the lenient answer is part of the decision asked for above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions