damienhaynes / moving-pictures

Moving Pictures is a movies plug-in for the MediaPortal media center application. The goal of the plug-in is to create a very focused and refined experience that requires minimal user interaction. The plug-in emphasizes usability and ease of use in managing a movie collection consisting of ripped DVDs, and movies reencoded in common video formats supported by MediaPortal.
12 stars 6 forks source link

Chunk encoded web response in FileBasedResource #1073

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Try to get a resource (image) from an HTTP server that send chunked response, 
for example: http://pad.mymovies.it/filmclub/2007/21/206/locandina.jpg

What is the expected output? What do you see instead?
The class enters in an infinite loop, continuosly reading the content from the 
web and appending it the the local file name, creating a huge file on the file 
system

What version of Moving Pictures are you using? What version of MediaPortal? 
What Skin?
I tested it with current stable version 1.2.3 of Moving Pictures, but I 
Searched in the source code of the current trunk, and the problem is still 
there.
MediaPortal version is 1.2.2, but I think it's not important for the bug.

I try to explain what I discovered.

When the FileBasedResource.Download(url) method is invoked, it starts 
downloading the image file, but as it's Chunk Encoded (Transfer-Encoding: 
chunked in the HTTP header) the Content-Length is assigned to "-1" by .NET.

Having so, the file is fully downloaded, but the next check you do for file 
completion:

                if (fileStream.Length != totalBytes) {
                    fileStream.Close();
                    fileStream = null;

                    rtn = DownloadStatus.INCOMPLETE;
                }

always returns "INCOMPLETE" because totalBytes is -1.

The result is that the file process of downloading starts again, and again, and 
every time the full image content is added to the local file (thinking that the 
previous download only ended prematurely) creating an always-increasing file, 
without end.

I think that when Content-Length is -1 an "easy" fix can be not to check for 
file completion, a more accurate one is to find another way to check when the 
file is really complete (as we don't have the length before the body reading) 
but as now I didn't find a good way to achieve this.

Thanks in advance.
Maurizio.

Original issue reported on code.google.com by mfocare1@gmail.com on 16 Jan 2012 at 2:07

GoogleCodeExporter commented 8 years ago

Original comment by conrad.john on 16 Jan 2012 at 7:37

GoogleCodeExporter commented 8 years ago
Applied patch provided by cyberfix in r1363. Many thanks cyberfix!

Original comment by conrad.john on 26 Feb 2012 at 4:45

GoogleCodeExporter commented 8 years ago
Thanks from me too for the good fix.
Bye.
Maurizio.

Original comment by mfocare1@gmail.com on 27 Feb 2012 at 11:33