From b735ef2cde0e5b982ff157aff59199eeca9b3a71 Mon Sep 17 00:00:00 2001
From: Pierre Ynard <linkfanel@yahoo.fr>
Date: Wed, 31 Aug 2022 09:39:18 +0200
Subject: [PATCH] youtube.lua: don't silently fail on "n" descrambling script
 parsing

The descrambling script section was updated from a simple and linear
chain of calls, to a complex execution tree with conditional branches.
Failure to recognize and parse this call structure (or lack thereof)
resulted in a silent no-op. Add a check to properly report an error.

Ref #27227
---
 share/lua/playlist/youtube.lua | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 153e591e8751..cc088326bbae 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -460,6 +460,10 @@ function n_descramble( nparam, js )
     -- as a second argument. We parse and emulate those calls to follow
     -- the descrambling script.
     -- c[40](c[14],c[2]),c[25](c[48]),c[14](c[1],c[24],c[42]()), [...]
+    if not string.match( script, "c%[(%d+)%]%(c%[(%d+)%]([^)]-)%)" ) then
+        vlc.msg.dbg( "Couldn't parse and execute YouTube video throttling parameter descrambling rules" )
+        return nil
+    end
     for ifunc, itab, args in string.gmatch( script, "c%[(%d+)%]%(c%[(%d+)%]([^)]-)%)" ) do
         local iarg1 = string.match( args, "^,c%[(%d+)%]" )
         local iarg2 = string.match( args, "^,[^,]-,c%[(%d+)%]" )
-- 
GitLab