Skip to content

Fail to decode interval with value bigger than int32 #8887

Closed
@DifferentialOrange

Description

@DifferentialOrange

It is allowed to create intervals with values bigger than int32 for minutes and seconds.

local MAX_MIN_RANGE = MAX_HOUR_RANGE * 60
local MAX_SEC_RANGE = MAX_DAY_RANGE * SECS_PER_DAY

Since doubles are used to store values, interval itself can process such big values.

struct interval {
/** Duration in seconds. */
double sec;
/** Number of minutes, if specified. */
double min;
/** Number of hours, if specified. */
double hour;
/** Number of days, if specified. */
double day;
/** Number of weeks, if specified. */
int32_t week;
/** Number of months, if specified. */
int32_t month;
/** Number of years, if specified. */
int32_t year;
/** Fraction part of duration in seconds. */
int32_t nsec;
/** Adjustment mode for day in month operations, @sa dt_adjust_t */
dt_adjust_t adjust;
};

Msgpack encoding also succeeds:

tarantool> msgpack.encode(datetime.interval.new{min=6184879877159}):hex()
---
- c70d060205cf000005a007916c270801
...

Yet msgpack decoding fails:

tarantool> msgpack.decode(msgpack.encode(datetime.interval.new{min=6184879877159}))
---
- error: 'msgpack.decode: invalid MsgPack'
...

The reason is that int32 is used to extract the value

if (mp_read_int32(data, &value) != 0)

while allowed values are not really restricted to int32. (For example, msgpack above has uint64 value for minutes.)

Metadata

Metadata

Labels

1spbugSomething isn't workingteamE

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions