xbmc / inputstream.ffmpegdirect

Supports streams opened by FFmpeg's libavformat or Kodi's cURL such as plain TS, HLS and DASH (non-DRM) as well as many others. There is support for Archive/Catchup services where there is a replay window and can timeshift across that span. Also provides timeshift for live streams where rewind/pause and fast-forward would not have been available.
GNU General Public License v2.0
57 stars 40 forks source link

Fix windows crash on %20N #246

Closed matthuisman closed 10 months ago

matthuisman commented 10 months ago

fixes https://github.com/xbmc/inputstream.ffmpegdirect/issues/229

matthuisman commented 10 months ago

@phunkyfish this fixes the crash for me

noticed the same av_dump was logged twice as well so removed one and then commented the other two

matthuisman commented 10 months ago

if i play the same stream with Kodi, it outputs image

notice the url it spits out doesnt have the user-agent on it like it does when output in ffmpegdirect

phunkyfish commented 10 months ago

Do you think it’s the GetRedactedCall() that causes the crash?

Or is it the ffmpeg dump call itself.

phunkyfish commented 10 months ago

FYI, you can ignore the errors for Apple platforms. That’s something else.

matthuisman commented 10 months ago

i put %20N in the url before | (https://i.mjh.nz/tvnz-1.m3u8#%20N ) and Kodi ffmpeg outputted it OK: Input #0, hls, from 'https://i.mjh.nz/tvnz-1.m3u8#%20N':

But exact same url crashed ffmpegdirect

that tells me its an issue in GetRedactedCall

matthuisman commented 10 months ago

there is a difference between direct and kodi using %20M (not N)

kodi: ffmpeg[0x1d6c2f6cd60]: Input #0, hls, from 'https://i.mjh.nz/tvnz-1.m3u8#%20M': direct: ffmpeg[3657D3A2]: Input #0, hls, from 'https://i.mjh.nz/tvnz-1.m3u8#M':

matthuisman commented 10 months ago
3-08-19 09:29:40.644 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: ffmpegdirect::FFmpegStream::Open - av_find_stream_info finished
2023-08-19 09:29:40.644 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream ID: 16
2023-08-19 09:29:40.645 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream ID: 17
2023-08-19 09:29:40.645 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream - discarding unknown stream with id: 18
2023-08-19 09:29:40.645 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: CDVDDemuxFFmpeg::AddStream - discarding unknown stream with id: 19
2023-08-19 09:29:40.645 T:27036   debug <general>: AddOnLog: inputstream.ffmpegdirect: redacted ok
matthuisman commented 10 months ago

seems like the redacted / code before that is not escaping the str correctly. If I use: https://i.mjh.nz/tvnz-1.m3u8#%%20NT i get: ffmpeg[D4B504F5]: Input #0, hls, from 'https://i.mjh.nz/tvnz-1.m3u8#%20NT': and it plays

But if I use https://i.mjh.nz/tvnz-1.m3u8|user-agent=Windows%%20NT then kodi crashes when its parsing the options

So i think maybe redacted is fine but it should be getting an already escaped string?

phunkyfish commented 10 months ago

So parsing the URL works correctly but parsing the options fails?

matthuisman commented 10 months ago

Double %% in url is ok but %% in user-agent crashes. %% is not a sufficient workaround anyway as it wouldnt work for Kodi ffmpeg or inputstream.adaptive.

Single % crashes in either url or user-agent

Maybe a urldecode is needed early on? Inputstream.adaptive has a urldecode method

phunkyfish commented 10 months ago

There are a few urlencode’s about, ffmpegdirect has one too I think. The real question is detecting when it needs to be applied. We don’t want to encode an already encoded URL.

Here it is: https://github.com/xbmc/inputstream.ffmpegdirect/blob/38aeb2f145897c06e36bd2fa057bcdf7a4a428bf/src/stream/url/URL.cpp#L829

phunkyfish commented 10 months ago

How about we cheat a little and just check for you your use case and encode in that one specific case and see does it work?

matthuisman commented 10 months ago

my use case is %20N in user-agent that crashes. %%20N also crashes in user-agent. So I see no easy way to workaround the issue unfortunately.

I've run out of time to debug this any further. hopefully someone eventually fixes :)

phunkyfish commented 10 months ago

Will try to get it running in a debugger and see can I figure out something.

phunkyfish commented 10 months ago

So I just set up the debugger and then realised it is a windows only issue. Facepalm.