From 087f1abd09498a77bbdb791d2d34de572aba814a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mantas=20Mikul=C4=97nas?= Date: Thu, 11 Jun 2020 21:55:24 +0300 Subject: [PATCH] no longer apply js-deflate workaround if not necessary --- getpaste | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/getpaste b/getpaste index 57ab061..293b91c 100755 --- a/getpaste +++ b/getpaste @@ -994,7 +994,8 @@ sub dl_privatebin { my $body = get($url) // return; $body = decode_json($body); - if ($body->{v} == 2) { + if ($body->{v} && $body->{v} == 2) { + _trace("redirecting to v2 unwrapper"); my $data = $body; $data = unwrap_privatebin_v2($data, $frag); return $data; @@ -1005,7 +1006,13 @@ sub dl_privatebin { $data = decode_base64($data); # The example code that comes with js-deflate mistakenly encodes binary # data as UTF-8, and of course PrivateBin just used it verbatim. - $data = encode("latin1", decode("utf-8", $data)); + # 2020-06-11: Apparently they changed to no longer use deflate. + if (eval {decode("utf-8", $data, &Encode::FB_CROAK)}) { + _trace("working around js-deflate binary data bug"); + $data = encode("latin1", decode("utf-8", $data)); + } else { + _trace("skipping js-deflate workaround"); + } $data = decompress_deflate($data); return $data; }