Skip to content

[CRITICAL BUG, UB] Signed left-shift overflow in sha1_transform #39

Description

@PavelSharp

As noted in #33 we have the same problem when building m[i]:

m[i] = (data[j] << 24) + (data[j + 1] << 16) + (data[j + 2] << 8) + (data[j + 3]);

So, an integer promotion is happening here, and subexpression data[j] << 24 may set the sign bit of a 32-bit (probably 32-bit) signed int.
Possible fixes:

  1. m[i] = ((WORD)data[j] << 24) + (data[j + 1] << 16) + (data[j + 2] << 8) + (data[j + 3]); similarly to Signed overflow undefined behavior in md5.c #33
  2. m[i] = ((WORD)data[j] << 24) | ((WORD)data[j + 1] << 16) | ((WORD)data[j + 2] << 8) | ((WORD)data[j + 3]);

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions