-
Notifications
You must be signed in to change notification settings - Fork 29
Document maximum input length #146
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
base: main
Are you sure you want to change the base?
Conversation
Out of curiosity, where are these "magic" numbers coming from? Is there any concern of adding a new format that suffers from overflow for values smaller than what is |
I'm assuming you mean
I'll have to ponder those alternatives, possibly using a mix like specifying
There's no concern. Those bounds are correct for all possible |
Yes. I think it's fine as is. While a number like a million is nice since it's a power of 10, it's still just as arbitrary. Additionally, I don't think it makes sense to be more limiting than necessary. If a person wants to work with a large buffer (e.g., 100 MiB on an x64 machine), then they should be allowed to so long as the code is still correct. Something like
I guess I'm not used to this level of performance concern. If you are worried about this level of performance, wouldn't it be better to define Anyway, I was trying to confirm my "guess" that these magic values were just "convenient" and not too unnecessarily limiting. Alternatively, you can perform checked arithmetic where overflow is possible (e.g., |
Fair point. So I'll keep the PR as is. The current limits are close enough to the actual ones (except for
I'm not sure if you're talking about the precise limits or those of the PR. I was talking about the precise limits when talking about complexity. And for those you can't compute the limits at compile-time because they depend on the
Exactly. Those limits strike a balance between "close enough to the implementation limit" and "simple enough for users and low enough to permit future implementations". I'm planning to improve the
That's something I considered. But this still has 2 of the 3 drawbacks listed above. Namely the limit will be hard to understand (very long formula) and leaks implementation details (possibly preventing future implementations). |
My experience with SemVer stuff is that going from
I was being somewhat hyperbolic with my analogy. I was stating that if calculating the precise limit is "too expensive", then why not go further and think
Well if we are already conceding that the cited limit is subject to change to a higher value without SemVer implications, then I'm not sure if those drawbacks really apply. In v2 things are a little tricky since it's reasonable—even necessary for people like me who intend to avoid
You can always provide a separate function that does
"Freeing" you from citing any implementation-based limits since it'd just be a convenience function that allows one to avoid calling The last choice is to re-define the length calculations such that overflow is not possible. Not sure how easy that is to do generally, but it's quite easy for specific encodings as the cited issue shows for base64url without padding. The algorithms for encoded length and decoded length were the algorithms I was using in my own code, but they're actually not correct since Footnotes
|
I was also of this opinion, but due to #126 I asked the community, and sadly that's not the general opinion. If a panic is documented, then it's a "positive" behavior.
I see. Then I don't think this holds.
That's a very good observation. In v3 I don't even need to document the limit. Returning an error is enough. But I can still provide a limit below which it will never error due to overflow (essentially some
That's simply not possible for |
Hm, interesting. Like most things, SemVer has a fair amount of subjectivity. The fact that you already have a generic "invalid length" variant for
While
I don't follow. When const fn base64url_nopad_encode_len(n: usize) -> usize {
const MAX_LEN: usize = isize::MAX as usize;
assert!(n <= MAX_LEN);
((n / 3) << 2) + ((n % 3) << 2).div_ceil(3)
} |
It's not.
But is this useful? If you assume the input fits |
Ah, I was lazily going by the constants that are defined (e.g.,
Well the point is moot since you correctly pointed out you support smaller formats than base16; nonetheless I'll reply. You currently don't remark anywhere that |
That's exactly why I'm only giving a simple limit. I don't think anything close to those limits is realistic. It's just technically correct to have a limit. |
Fixes #145
Timeline:
data-encoding-v2.10.0
.