Repository navigation
Return an error instead of panicking on invalid transform-origin - #65
Open
ChrisJr404 wants to merge 1 commit into
Open
ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
TransformOrigin::from_str could hit an unreachable!() and panic on trivial inputs such as " ", "\t", "-", or "+". When the first component fails to parse, the underlying skip_spaces/sign handling can still advance the stream to its end, so both follow-up blocks are skipped and the final match falls through to the unreachable arm with no parsed arguments. Return TransformOriginError::InvalidParameters for that case and add regression tests covering the offending inputs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TransformOrigin::from_strcan panic on a number of short, otherwise-innocuous inputs. For example:Each of these hits the
unreachable!()arm:Why it happens
At the top of
from_strwe bail out early only when the input is completely empty. For a non-empty input the first component is parsed withparse_part, which triesparse_directional_positionand thenparse_length.parse_lengthcallsskip_spaces()(and consumes a leading sign) before it fails, so on an input like" "or"-"the parse returnsErr/Nonebut the stream cursor has already advanced to the end.Because the stream is now at its end, both of the
if !stream.at_end()blocks that would parse the second and third components are skipped, leavingfirst_arg == Noneandsecond_arg == third_arg == None. The finalmatchonly handles the(Some, None, None)and(Some, Some, _)shapes, so this falls through to_ => unreachable!()and panics.Since
from_strruns on untrusted attribute values (e.g. atransform-originpresentation attribute), a caller that does not wrap the parse incatch_unwindcan be taken down by a one-byte input.Fix
Return the already-defined
TransformOriginError::InvalidParametersfor that fall-through case instead of panicking. Valid inputs are unaffected — they always produce aSomefirst component and hit the existing arms.Added regression tests for
" "," ","\t","-", and"+". The full test suite passes andcargo fmt/cargo clippy --lib --testsare clean.