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 #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).