Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process: fix two overflow cases in SourceMap VLQ decoding #31490

Closed
wants to merge 3 commits into from

Commits on Jan 24, 2020

  1. process: fix two overflow cases in SourceMap VLQ decoding

    These both have to do with extremely large numbers, so it's unlikely to
    cause a problem in practice. Still, correctness.
    
    First, encoding `-2147483648` in VLQ returns the value `"B"`. When
    decoding, we get the value `1` after reading the base64. We then check
    if the first bit is set (it is) to see if we should negate it, then we
    shift all bits right once. Now, `value` will be `0` and `negate` will
    be `true`. So, we'd return `-0`. Which is a bug! `-0` isn't
    `-2147483648`, and we've broken a round trip.
    
    Second, encoding any number with the 31st bit set, we'd return the
    opposite sign. Let's use `1073741824`. Encoding, we get `"ggggggC"`.
    When decoding, we get the value `-2147483648` after reading the base64.
    Notice, it's already negative (the 32nd bit is set, because the 31st was
    set and we shifted everything left once). We'd then check the first bit
    (it's not) and shift right. But we used `>>`, which does not shift the
    sign bit. We actually wanted `>>>`, which will. Because of that bug, we
    get back `-1073741824` instead of the positive `1073741824`. It's even
    worse if the 32nd and 31st bits are set, `-1610612736` becomes
    `536870912` after a round trip.
    
    I recently fixed the same two bugs in Closure Compiler:
    google/closure-compiler@584418eb
    jridgewell committed Jan 24, 2020
    Copy the full SHA
    ec03394 View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2020

  1. Copy the full SHA
    78e7088 View commit details
    Browse the repository at this point in the history
  2. process: avoid 0x80000000

    jridgewell committed Jan 25, 2020
    Copy the full SHA
    9d83dbd View commit details
    Browse the repository at this point in the history