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

Fix UTF-8 unsoundness in string::merge #194

Merged
merged 3 commits into from
Jun 11, 2019

Commits on Jun 9, 2019

  1. Merge string value without as_mut_vec unsoundness

    In case of an encoding error in string::merge, the appended string value
    is left with broken UTF-8 in case of an error. The same can happen if
    any of the Buf methods panics. This results in UB if the string value is used
    after the error return or in unwind, respectively.
    
    Change the implementation to truncate the string back to valid UTF-8
    content in any code path that does not go through validation of the
    newly appended bytes.
    mzabaluev committed Jun 9, 2019
    Configuration menu
    Copy the full SHA
    55f644e View commit details
    Browse the repository at this point in the history
  2. Unit test for string::merge failure

    Test that adding an invalid UTF-8 sequence results in an error,
    and that the string is reverted to its state prior to the merge call.
    mzabaluev committed Jun 9, 2019
    Configuration menu
    Copy the full SHA
    8c6f640 View commit details
    Browse the repository at this point in the history

Commits on Jun 10, 2019

  1. Safe reimplementation of string::merge

    As suggested by Dan Burkert:
    https://github.com/danburkert/prost/pull/194#discussion_r292096009
    
    The existing string value is dropped in case of a merge failure,
    but this is better than exposing an invalid value.
    mzabaluev committed Jun 10, 2019
    Configuration menu
    Copy the full SHA
    8762942 View commit details
    Browse the repository at this point in the history