Skip to content

Fix out of bounds access in unsafeCodePointAt0Fallback #112

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

Merged
merged 2 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "eslint src && pulp build -- --censor-lib --strict",
"test": "pulp test",
"test": "pulp test && npm run test:run:without_codePointAt",
"test:run:without_codePointAt": "node -e \"delete String.prototype.codePointAt; require('./output/Test.Main/index.js').main();\"",
"bench:build": "purs compile 'bench/**/*.purs' 'src/**/*.purs' 'bower_components/*/src/**/*.purs'",
"bench:run": "node --expose-gc -e 'require(\"./output/Bench.Main/index.js\").main()'",
"bench": "npm run bench:build && npm run bench:run"
Expand Down
10 changes: 6 additions & 4 deletions src/Data/String/CodePoints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ unsafeCodePointAt0Fallback :: String -> CodePoint
unsafeCodePointAt0Fallback s =
let
cu0 = fromEnum (Unsafe.charAt 0 s)
cu1 = fromEnum (Unsafe.charAt 1 s)
in
if isLead cu0 && isTrail cu1
then unsurrogate cu0 cu1
else CodePoint cu0
if isLead cu0 && CU.length s > 1
then
let cu1 = fromEnum (Unsafe.charAt 1 s) in
if isTrail cu1 then unsurrogate cu0 cu1 else CodePoint cu0
else
CodePoint cu0