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

壊れた文字列があった場合、そこで変換が切れた変換後文字列になる可能性 #8

Open
tgk1 opened this issue Dec 18, 2019 · 1 comment

Comments

@tgk1
Copy link

tgk1 commented Dec 18, 2019

NKF.swiftの

let out: (UnsafeMutablePointer<UInt8>, Int) = convert(src: src, length: length, options: newOptions)
からの
let ptr = UnsafeMutableRawPointer(out.0).assumingMemoryBound(to: CChar.self)
についてです。

ここでout.0内に壊れた文字列があってNULL終端っぽい扱いをされると、ptrが意図しないところで終わるような気がします。
そもそも不正なデータを送るのはアレですが。

let str = String(bytesNoCopy: ptr, length: out.1 - 1, encoding: .utf8, freeWhenDone: false)
とかサイズ指定をすると影響は最小限になると思います。

@novi
Copy link
Owner

novi commented Sep 11, 2020

ご連絡ありがとうございます。 0.5.0 にて修正してみました。Foundation側のソースを見る限り、String作成時にUTF8のバリデーションが行われないので、パフォーマンスは良くなるかもしれません。UTF8のバリデーションを行うには、.strict オプションを使うことができます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants