Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

The codec.encode function encodes larger than expected integers #8968

Closed
Tracked by #7245
ishantiw opened this issue Sep 13, 2023 · 0 comments
Closed
Tracked by #7245

The codec.encode function encodes larger than expected integers #8968

ishantiw opened this issue Sep 13, 2023 · 0 comments

Comments

@ishantiw
Copy link
Contributor

Description

The encode function of the Codec class successfully encodes integers larger than expected.

Calling the decode method of the Codec class on this encoded data fails, breaking the round-trip property of the encode and decode functions.

Recommendation: Add checks in the code to prevent integers larger than the maximum value or smaller than the minimum value cannot be encoded or decoded.

Steps to reproduce

This issue can be replicated with the test shown below, in which a value of 2100 is successfully encoded as a uint64 (while the maximum value should be 264-1).

describe('uint_validation', () => {
    const schema_uint64 = {
        $id: 'test/uint_validation',
        type: 'object',
        required: ['amount'],
        properties: {
            amount: {
                dataType: 'uint64',
                fieldNumber: 1,
            },
}, };
    it('uint64 encoding with larger than expected values', () => {
         expect(codec.encode(schema_uint64, { amount: BigInt(2) ** BigInt(100) })).toThrow(); // This does not throw
    });
});

Which version(s) does this affect? (Environment, OS, etc...)

v6.1.0-beta.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants