Skip to content

🐛 Use Range#size vs Range#count for uid-set limit #411

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 1 commit into from
Feb 26, 2025
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
2 changes: 1 addition & 1 deletion lib/net/imap/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ def uid_set
when T_NUMBER then [Integer(token.value)]
when T_ATOM
entries = uid_set__ranges(token.value)
if (count = entries.sum(&:count)) > MAX_UID_SET_SIZE
if (count = entries.sum(&:size)) > MAX_UID_SET_SIZE
parse_error("uid-set is too large: %d > 10k", count)
end
entries.flat_map(&:to_a)
Expand Down
7 changes: 7 additions & 0 deletions test/net/imap/test_imap_response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ def test_uidplus_copyuid__too_large
"A004 OK [copyUID 1 10000:20000,1 1:10001] Done\r\n"
)
end
Timeout.timeout(1) do
assert_raise Net::IMAP::ResponseParseError, /uid-set is too large/ do
parser.parse(
"A004 OK [copyUID 1 1:#{2**32 - 1} 1:#{2**32 - 1}] Done\r\n"
)
end
end
end

end