Skip to content

Int32 overflow when creating a buffer #12553

Closed

Description

@rgrannell1

I noticed that there's an unhandled overflow error in stream.Readable in work earlier today; when large values are supplied as highWaterMark the value used by the created object wraps around to a negative number. This didn't cause us massive problems, but it is a little difficult to debug (given that most people won't read the contents of _readableState)

console.log(
	require('stream').Readable({
		highWaterMark: 2147483647
	})._readableState.highWaterMark
)

console.log(
	require('stream').Readable({
		highWaterMark: 2147483647 + 1
	})._readableState.highWaterMark
)

which outputs:

2147483647
-2147483648

This should ideally throw an error, or support larger numeric values.

Activity

  1. cjihrig commented on Apr 20, 2017

    @cjihrig
    Contributor

    You may be running into these lines.

    > ~~(2147483647)
    2147483647
    > ~~(2147483647 + 1)
    -2147483648
    
  2. tniessen commented on Apr 20, 2017

    @tniessen
    Member

    @cjihrig Was about to write the same thing, appears to be the problem.

  3. added
    confirmed-bugIssues and PRs for confirmed bugs.
    streamIssues and PRs related to Node.js streams.
    on Apr 20, 2017
  4. tniessen commented on Apr 22, 2017

    @tniessen
    Member

    This should ideally throw an error, or support larger numeric values.

    Thoughts on this? 2^31 is a fairly high value for highWaterMark. Is there any real-world use for bigger values?

  5. cjihrig commented on Apr 22, 2017

    @cjihrig
    Contributor

    I'd personally be in favor of some input validation, but I'd like to know what @nodejs/streams thinks.

  6. mcollina commented on Apr 22, 2017

    @mcollina
    SponsorMember

    I'm definitely +1 for input validation. That large value is really a bug, because you are essentially disabling backpressure, and you are exposing yourself to out-of-memory errors.

  7. mcollina commented on May 16, 2017

    @mcollina
    SponsorMember

    Fixed in #12593.

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

    confirmed-bugIssues and PRs for confirmed bugs.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions