-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixes #4060 #4068
Fixes #4060 #4068
Conversation
src/gzip/header.cr
Outdated
@@ -71,7 +73,7 @@ class Gzip::Header | |||
|
|||
# flg | |||
flg = Flg::None | |||
flg |= Flg::EXTRA if @extra | |||
flg |= Flg::EXTRA if !@extra.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use unless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have done...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
src/gzip/header.cr
Outdated
@@ -85,8 +87,8 @@ class Gzip::Header | |||
# os | |||
io.write_byte os | |||
|
|||
if extra = @extra | |||
io.write_byte extra.size.to_u8 | |||
if [email protected]? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
Thanks, I was about to suggest the same (or |
No, this fix is a workaround, the real issue is a compiler bug. @extra is always initialized, it has an initializer |
src/gzip/header.cr
Outdated
@@ -44,6 +44,8 @@ class Gzip::Header | |||
xlen = io.read_byte.not_nil! | |||
@extra = Bytes.new(xlen) | |||
io.read_fully(@extra) | |||
else | |||
@extra = Bytes.empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not needed, @extra
should always be initialized. Right now it doesn't work because of #3988
Sorry, I closed it too soon. The fix is OK, the but adding an |
Ok will update. |
Oh, actually 👍 to |
|
Changed it back to empty - this only runs once per gzip operation... doubt the speed difference would be significant compared to everything else in the zipping process, but I was happy with |
@crisward Ah, my comment is misleading indeed, sorry. The point is that |
Ok, new to ruby/crystal so didn't know what |
Oh, sorry @asterite, I just assumed that |
Oh, I always assumed |
In practice it works the same if the elements will always be truthy. The problem is that |
src/gzip/header.cr
Outdated
if extra = @extra | ||
io.write_byte extra.size.to_u8 | ||
unless @extra.empty? | ||
io.write_byte @extra.size.to_u8 | ||
io.write(extra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this also refer to @extra
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think you're right. It used to copy the value, I'm guessing there isn't a test case for gzip with extra set. I'll update.
This sounds like it may also fix #4064 |
Related to #4084 as well? |
Extra byte evaluated to truthy with an empty slice. Added size check which fixes the gzip bug.
I'll remove my previous pull request.