Package: release.debian.org
Severity: normal
Tags: bookworm
User: release.debian....@packages.debian.org
Usertags: pu

Dear release team,

[ Reason ]

The version of lgogdownloader in stable crashes with current URLs used
in GOG; see #1085527 for an example. This renders the package
unusable.

[ Impact ]

Users can no longer download artifacts using lgogdownloader, which is
the package’s sole purpose.

[ Tests ]

The proposed fix is the fix implemented upstream; see
https://github.com/Sude-/lgogdownloader/issues/279 for details. The
patches apply as-is to the version in Bookworm; see
https://github.com/Sude-/lgogdownloader/commit/52b8bdc8fa0028bcb875c6a723c6e04deeecbcb8
and
https://github.com/Sude-/lgogdownloader/commit/6556dc6a82b4e3d64ef1a7940736be3a7b2ac956

The fix is already available in unstable (it’s included in version
3.15) and works there. 3.9 with these patches builds and works fine; I
can reproduce the bug and verify that the suggested patch fixes it.

[ Risks ]

The fix seems straightforward enough to me. In any case the package is
already broken, making it worse won’t make the situation worse for
users.

[ Checklist ]
  [x] *all* changes are documented in the d/changelog
  [x] I reviewed all changes and I approve them
  [x] attach debdiff against the package in (old)stable
  [x] the issue is verified as fixed in unstable

[ Changes ]

The changes add a number of checks to the
galaxyAPI::getPathFromDownloadUrl function to handle new components
found in URLs.

[ Other info ]

Nothing I can think of!

Regards,

Stephen
diff --git a/debian/changelog b/debian/changelog
index a798d46..1cb1f94 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+lgogdownloader (3.9-2+deb12u1) bookworm; urgency=medium
+
+  * Apply upstream fixes for parsing Galaxy URLs. Closes: #1085527.
+
+ -- Stephen Kitt <sk...@debian.org>  Sun, 20 Oct 2024 21:39:20 +0200
+
 lgogdownloader (3.9-2) unstable; urgency=medium
 
   * qtwebengine5-dev is now available on mips64el, use it there. Thanks
diff --git a/debian/patches/galaxy-urls-1.patch 
b/debian/patches/galaxy-urls-1.patch
new file mode 100644
index 0000000..bcc5a24
--- /dev/null
+++ b/debian/patches/galaxy-urls-1.patch
@@ -0,0 +1,24 @@
+commit 52b8bdc8fa0028bcb875c6a723c6e04deeecbcb8
+Author: Sude <lgogdownloa...@gmail.com>
+Date:   Thu Aug 22 18:13:44 2024 +0300
+
+    Fix galaxyAPI::getPathFromDownlinkUrl with Fastly CDN urls
+    
+    Fastly CDN urls don't contain query strings
+
+diff --git a/src/galaxyapi.cpp b/src/galaxyapi.cpp
+index 56d5745..7699d69 100644
+--- a/src/galaxyapi.cpp
++++ b/src/galaxyapi.cpp
+@@ -567,6 +567,11 @@ std::string galaxyAPI::getPathFromDownlinkUrl(const 
std::string& downlink_url, c
+     else
+         filename_end_pos = downlink_url_unescaped.find_first_of("?");
+ 
++    // Downlink doesn't contain "?path=" or "?"
++    // Set end pos to length
++    if (filename_end_pos == std::string::npos)
++        filename_end_pos = downlink_url_unescaped.length();
++
+     if (downlink_url_unescaped.find("/" + gamename + "/") != 
std::string::npos)
+     {
+         
path.assign(downlink_url_unescaped.begin()+downlink_url_unescaped.find("/" + 
gamename + "/"), downlink_url_unescaped.begin()+filename_end_pos);
diff --git a/debian/patches/galaxy-urls-2.patch 
b/debian/patches/galaxy-urls-2.patch
new file mode 100644
index 0000000..8d32f26
--- /dev/null
+++ b/debian/patches/galaxy-urls-2.patch
@@ -0,0 +1,88 @@
+commit 6556dc6a82b4e3d64ef1a7940736be3a7b2ac956
+Author: Sude <lgogdownloa...@gmail.com>
+Date:   Thu Aug 22 21:50:23 2024 +0300
+
+    Add more checks to galaxyAPI::getPathFromDownlinkUrl
+
+diff --git a/src/galaxyapi.cpp b/src/galaxyapi.cpp
+index 7699d69..716ebdd 100644
+--- a/src/galaxyapi.cpp
++++ b/src/galaxyapi.cpp
+@@ -547,40 +547,51 @@ std::string galaxyAPI::getPathFromDownlinkUrl(const 
std::string& downlink_url, c
+ {
+     std::string path;
+     std::string downlink_url_unescaped = 
(std::string)curl_easy_unescape(curlhandle, downlink_url.c_str(), 
downlink_url.size(), NULL);
++    size_t filename_start_pos = 0;
+ 
+-    // GOG has changed the url formatting few times between 2 different 
formats.
+-    // Try to get proper file name in both cases.
+-    size_t filename_end_pos;
+-    if (downlink_url_unescaped.find("?path=") != std::string::npos)
++    // If url ends in "/" then remove it
++    if (downlink_url_unescaped.back() == '/')
++        downlink_url_unescaped.assign(downlink_url_unescaped.begin(), 
downlink_url_unescaped.end()-1);
++
++    // Assume that filename starts after last "/" in url
++    if (downlink_url_unescaped.find_last_of("/") != std::string::npos)
++        filename_start_pos = downlink_url_unescaped.find_last_of("/") + 1;
++
++    // Url contains "/gamename/"
++    if (downlink_url_unescaped.find("/" + gamename + "/") != 
std::string::npos)
++        filename_start_pos = downlink_url_unescaped.find("/" + gamename + 
"/");
++
++    // Assume that filename ends at the end of url
++    size_t filename_end_pos = downlink_url_unescaped.length();
++
++    // Check to see if url has any query strings
++    if (downlink_url_unescaped.find("?") != std::string::npos)
+     {
+-        size_t token_pos = downlink_url_unescaped.find("&token=");
+-        size_t access_token_pos = 
downlink_url_unescaped.find("&access_token=");
+-        if ((token_pos != std::string::npos) && (access_token_pos != 
std::string::npos))
+-        {
+-            filename_end_pos = std::min(token_pos, access_token_pos);
+-        }
+-        else
++        // Assume that filename ends at first "?"
++        filename_end_pos = downlink_url_unescaped.find_first_of("?");
++
++        // Check for "?path="
++        if (downlink_url_unescaped.find("?path=") != std::string::npos)
+         {
+-            filename_end_pos = downlink_url_unescaped.find_first_of("&");
++            size_t token_pos = downlink_url_unescaped.find("&token=");
++            size_t access_token_pos = 
downlink_url_unescaped.find("&access_token=");
++            if ((token_pos != std::string::npos) && (access_token_pos != 
std::string::npos))
++            {
++                filename_end_pos = std::min(token_pos, access_token_pos);
++            }
++            else
++            {
++                if (downlink_url_unescaped.find_first_of("&") != 
std::string::npos)
++                    filename_end_pos = 
downlink_url_unescaped.find_first_of("&");
++            }
+         }
+     }
+-    else
+-        filename_end_pos = downlink_url_unescaped.find_first_of("?");
+ 
+-    // Downlink doesn't contain "?path=" or "?"
+-    // Set end pos to length
+-    if (filename_end_pos == std::string::npos)
+-        filename_end_pos = downlink_url_unescaped.length();
++    path.assign(downlink_url_unescaped.begin()+filename_start_pos, 
downlink_url_unescaped.begin()+filename_end_pos);
+ 
+-    if (downlink_url_unescaped.find("/" + gamename + "/") != 
std::string::npos)
+-    {
+-        
path.assign(downlink_url_unescaped.begin()+downlink_url_unescaped.find("/" + 
gamename + "/"), downlink_url_unescaped.begin()+filename_end_pos);
+-    }
+-    else
+-    {
+-        
path.assign(downlink_url_unescaped.begin()+downlink_url_unescaped.find_last_of("/")+1,
 downlink_url_unescaped.begin()+filename_end_pos);
++    // Make sure that path contains "/gamename/"
++    if (path.find("/" + gamename + "/") == std::string::npos)
+         path = "/" + gamename + "/" + path;
+-    }
+ 
+     // Workaround for filename issue caused by different (currently unknown) 
url formatting scheme
+     // https://github.com/Sude-/lgogdownloader/issues/126
diff --git a/debian/patches/series b/debian/patches/series
index 4c469df..f993a5c 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,4 @@
 manpage-whatis.patch
 reproducible.patch
+galaxy-urls-1.patch
+galaxy-urls-2.patch

Reply via email to