Bug 12616 – AssertError in std.utf.decode

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-22T19:54:00Z
Last change time
2014-04-23T19:33:26Z
Assigned to
nobody
Creator
dmitrycvet

Attachments

IDFilenameSummaryContent-TypeSize
1347utfbug.torrentFrament of torrent file with bug (binary data)application/x-bittorrent14936

Comments

Comment #0 by dmitrycvet — 2014-04-22T19:54:18Z
Created attachment 1347 Frament of torrent file with bug (binary data) I use std.utf.validate to check validity string of UTF. And i catch UTFException if string not valid. But... In debug mode i have AssertError: [email protected](950): Assertion failure My code: try { root.str = cast(string) store.str; // from immutable(ubyte)[] validate(root.str); } catch(UTFException e) { root.str = toHexString!(LetterCase.upper)(store.str); } It work on release mode.
Comment #1 by andrej.mitrovich — 2014-04-23T19:08:19Z
Interesting problem. I think decode is wrong in using asserts here. asserts are for checking program state, enforce is for checking input. So I think the assert should be changed to: enforceEx!UTFException(isValidDchar(result)); Or something similar. monarchdodra what do you think?
Comment #2 by monarchdodra — 2014-04-23T19:21:10Z
(In reply to Andrej Mitrovic from comment #1) > Interesting problem. I think decode is wrong in using asserts here. asserts > are for checking program state, enforce is for checking input. So I think > the assert should be changed to: > > enforceEx!UTFException(isValidDchar(result)); > > Or something similar. monarchdodra what do you think? I think decode is supposed to throw an exception when it does decode an invalid character (and usually does). The assert is thrown in a "out" contract. If it triggers, it means decode has failed to detect the bad character. The assert itself shouldn't actually be changed, it just means there's an internal bug. Now, we need to figure out which character is being thrown, and how it "passed through the decode net". Interesting problem. I'll investigate.
Comment #3 by monarchdodra — 2014-04-23T19:22:05Z
(In reply to Andrej Mitrovic from comment #1) > Interesting problem. I think decode is wrong in using asserts here. asserts > are for checking program state, enforce is for checking input. So I think > the assert should be changed to: > > enforceEx!UTFException(isValidDchar(result)); > > Or something similar. monarchdodra what do you think? BTW: How did you tag me? Did you simply add my email to the cc list?
Comment #4 by monarchdodra — 2014-04-23T19:29:52Z
BTW, this seems resolved in HEAD. Didn't Dmitry fix this? Let me look up the pull...
Comment #5 by monarchdodra — 2014-04-23T19:32:15Z
Ah! There we go! https://github.com/D-Programming-Language/phobos/pull/2038 Closing as resolved duplicate of resolved issue 12419. *** This issue has been marked as a duplicate of issue 12419 ***
Comment #6 by andrej.mitrovich — 2014-04-23T19:33:26Z
(In reply to monarchdodra from comment #3) > BTW: How did you tag me? Did you simply add my email to the cc list? I searched for your e-mail on github and added you to the cc list. Hope you don't mind (I thought you'd know about this UTF stuff).