Skip to content

Fix panic when encoding undef scalars#66

Merged
dankogai merged 1 commit intodankogai:masterfrom
joyrex2001:master
Sep 29, 2016
Merged

Fix panic when encoding undef scalars#66
dankogai merged 1 commit intodankogai:masterfrom
joyrex2001:master

Conversation

@joyrex2001
Copy link
Copy Markdown

This pull request will fix the "panic: sv_setpvn called with negative strlen at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/Encode/Encoder.pm line 84" error, when you will try to Encoder::encode a undefined scalar. See also the accompanied unit test (t/undef.t).

@pali
Copy link
Copy Markdown
Contributor

pali commented Sep 26, 2016

That is not fix! It just hides this bug, which is probably in Encode.xs.

If you call ->encode method directly on object then it will still crash.

So please drop this patch

@pali
Copy link
Copy Markdown
Contributor

pali commented Sep 26, 2016

Real problem is in Encode.xs, Method_encode_xs at line:

if (src == &PL_sv_undef || SvROK(src)) src = sv_2mortal(newSV(0));

This does not handle undefined values correctly.

@pali
Copy link
Copy Markdown
Contributor

pali commented Sep 28, 2016

Looks like this problem is related to these reported bugs:
https://rt.cpan.org/Public/Bug/Display.html?id=117158
https://rt.cpan.org/Public/Bug/Display.html?id=65541

@dankogai dankogai merged commit d69edff into dankogai:master Sep 29, 2016
@pali
Copy link
Copy Markdown
Contributor

pali commented Sep 29, 2016

!!!! Why merging? This patch is totally incorrect! I suggest to immediately revert it and it fix properly!

@dankogai
Copy link
Copy Markdown
Owner

dankogai commented Sep 29, 2016

The fix may not be perfect but I wanted to merge the test.

Also note that the encoder object that find_encoding() return may not be Encode::XS object so I consider this patch worth merging. Fixing Encode.xs is a different issue.

pali added a commit to pali/p5-encode that referenced this pull request Oct 26, 2016
…ment in all XS functions

Before this patch every function XS function did it differently and not
every one correctly. Now SvPV_force_nomg() is used when source argument
is going to be modified. SvGETMAGIC() is called when entering into
functions and then only "nomg" variants of perl functions are used to
prevent processing get magic more times. SvSETMAGIC() is called after
modification of source argument.

This fixes bugs:
https://rt.cpan.org/Public/Bug/Display.html?id=117158
https://rt.cpan.org/Public/Bug/Display.html?id=85489
dankogai#66
@pali
Copy link
Copy Markdown
Contributor

pali commented Oct 26, 2016

Proper fix is here: #70

rurban pushed a commit to rurban/p5-encode that referenced this pull request May 10, 2019
…ment in all XS functions

Before this patch every function XS function did it differently and not
every one correctly. Now SvPV_force_nomg() is used when source argument
is going to be modified. SvGETMAGIC() is called when entering into
functions and then only "nomg" variants of perl functions are used to
prevent processing get magic more times. SvSETMAGIC() is called after
modification of source argument.

This fixes bugs:
https://rt.cpan.org/Public/Bug/Display.html?id=117158
https://rt.cpan.org/Public/Bug/Display.html?id=85489
dankogai#66
khwilliamson pushed a commit to khwilliamson/p5-encode that referenced this pull request May 2, 2020
…ment in all XS functions

Before this patch every function XS function did it differently and not
every one correctly. Now SvPV_force_nomg() is used when source argument
is going to be modified. SvGETMAGIC() is called when entering into
functions and then only "nomg" variants of perl functions are used to
prevent processing get magic more times. SvSETMAGIC() is called after
modification of source argument.

This fixes bugs:
https://rt.cpan.org/Public/Bug/Display.html?id=117158
https://rt.cpan.org/Public/Bug/Display.html?id=85489
dankogai#66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants