Libdvdread misses hidden files and causes segfaults to calling programs

Bug #852345 reported by rickyrockrat
54
This bug affects 9 people
Affects Status Importance Assigned to Milestone
libdvdread (Ubuntu)
Fix Released
High
Bryce Harrington
Natty
Fix Released
High
Bryce Harrington

Bug Description

[Impact]
Program segfaults when reading metadata of DVDs with invalid unicode characters.

This has been spotted with the quite popular Thor DVD, and several duplicate reports indicate it's affecting quite a few people. It's unknown if this was an accident (which would be bad enough!) or intentional (in which case we can expect more movies to be released with this flaw).

[Development Fix]
The patch is essentially scanning the upper of the two-byte code for unicode16 strings and if it has any non-zero value it blanks out the remainder of the string. In this particular case, this results in an empty string, thus causing the garbage file to be ignored.

The patch has been slightly modified from the original author's version, to clean up the code so the patch will be more maintainable.

[Stable Fix]
Oneiric and Natty carry the same version of libdvdread, so the same patch is used in both cases.

[Test Case]
1. Buy Thor DVD.
2. Install and run lsdvd.
3. Program segfaults

With the patch, step #3 produces valid output listing the contents of the DVD.

[Regression Potential]
Minor. This only affects how unicode characters in filenames on a DVD are handled, and as far as I know DVDs don't tend to use unicode. If they do use unicode, we can expect they'd use valid unicode (which this patch allows through.)

Since uploading the fix for this bug about a week ago, only one bug report has been filed against oneiric, and that bug is just a duplicate of this one.

[Original Report]
Package: libdvdread4
Version: 4.1.x and others

No error message, but symptoms are usually segfault when reading, for example the Movie DVD Thor.
This results from a new anti-copy scheme where the real video_ts.ifo is hidden. Use of the decoy video_ts.ifo results in a unplayable DVD.

Discussion is here:
http://ubuntuforums.org/showthread.php?p=11257764

Patch is here:

diff -ru libdvdread-4.1.3/src/dvd_udf.c libdvdread-4.1.3.fixed/src/dvd_udf.c
--- libdvdread-4.1.3/src/dvd_udf.c 2008-09-06 15:55:51.000000000 -0600
+++ libdvdread-4.1.3.fixed/src/dvd_udf.c 2011-09-16 14:07:04.000000000 -0600
@@ -331,21 +331,26 @@
 /* This is wrong with regard to endianess */
 #define GETN(p, n, target) memcpy(target,&data[p], n)

-static int Unicodedecode( uint8_t *data, int len, char *target )
+static int Unicodedecode(uint8_t *data, int len, char *target)
 {
- int p = 1, i = 0;
+ len--;
+ data++;
+ if (data[-1] == 8 )
+ memcpy(target, data, len);
+ else if (data[-1] == 16) {
+ int i;

- if( ( data[ 0 ] == 8 ) || ( data[ 0 ] == 16 ) ) do {
- if( data[ 0 ] == 16 ) p++; /* Ignore MSB of unicode16 */
- if( p< len ) {
- target[ i++ ] = data[ p++ ];
+ for (i = 0; i< len; i++) {
+ if (data[i*2] == 0)
+ target[i] = data[i*2+1];
+ else
+ target[i] = 0;
         }
- } while( p< len );
+ }
+ target[len] = '\0';

- target[ i ] = '\0';
     return 0;
 }
-
 static int UDFDescriptor( uint8_t *data, uint16_t *TagID )
 {
     *TagID = GETN2(0);

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in libdvdread (Ubuntu):
status: New → Confirmed
Revision history for this message
dc (darkcharl) wrote :

Was this reported to upstream (<email address hidden>)?

Revision history for this message
rickyrockrat (rickyrockrat) wrote :

No it wasn't. There hasn't been any activity on this library for two years. I'll report it.

Revision history for this message
dc (darkcharl) wrote :

Just for my own sakes (testing) I created a debdiff and a new package with the patch added. I'll attach the debdiff to this ticket in case others would like to use it.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "debdiff with the changes" of this bug report has been identified as being a patch in the form of a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-sponsors please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
Daniel Holbach (dholbach) wrote :
Bryce Harrington (bryce)
Changed in libdvdread (Ubuntu):
status: Confirmed → Triaged
importance: Undecided → High
Bryce Harrington (bryce)
Changed in libdvdread (Ubuntu Natty):
importance: Undecided → High
status: New → Triaged
Revision history for this message
Bryce Harrington (bryce) wrote :

I've reviewed and experimented with the patch, and on natty have reproduced both the original problem and fix. Let me also express gratitude to jim sixtyfive for the fix.

The patch is essentially scanning the upper of the two-byte code for unicode16 strings and if it has any non-zero value it blanks out the remainder of the string. In this particular case, this results in an empty string, thus causing the garbage file to be ignored.

The patch also improves the existing coding style, by using memcpy instead of manual do {} while pointer copy.

However, some of the coding style in the patch seemed a bit sketchy to me; for instance "data[-1]" feels like trouble waiting to happen; it works as coded, but could bite some future maintainer if they're not aware of it. I've gone ahead and fixed this, and added some comments and stuff to make the code clearer. I've tested this both with a dvd that expresses this bug, and one normal one, and both worked properly.

Here is a PPA with both natty and oneiric packages of this fix:

  https://launchpad.net/~bryce/+archive/lp852345

Revision history for this message
Bryce Harrington (bryce) wrote :

This patch looks suitable to me for backporting to natty as an SRU. If anyone would like to see this done, please test the ~natty package in the PPA from my prior comment with a sampling of DVDs which had been working properly before (I don't need to know the names, just tell me the number of different ones tested). If this is seen to cause no regressions, we can try posting it for SRU to natty in a few weeks.

Changed in libdvdread (Ubuntu Natty):
assignee: nobody → Bryce Harrington (bryce)
Changed in libdvdread (Ubuntu):
assignee: nobody → Bryce Harrington (bryce)
Changed in libdvdread (Ubuntu Natty):
status: Triaged → In Progress
Revision history for this message
Bryce Harrington (bryce) wrote :

As mentioned by the patch author, while this fixes the segfault and the software is able to read the dvd metadata correctly, there still seems to be some other issues. Running 'dvdbackup -M' on it seems to get stuck and copy indefinitely until ^C'd. Even so, the backup appears to play correctly. I'm going to assume this is a separate unrelated bug.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libdvdread - 4.1.3-10ubuntu4

---------------
libdvdread (4.1.3-10ubuntu4) oneiric; urgency=low

  * debian/patches/101-fix-msb-unicode.patch: Fixes unicode issue encountered
    when playing DVDs with newer protection. Thanks to Jim "sixtyfive"
    (LP: #852345)
 -- Robert BARABAS <dc@0xdc.org> Sun, 18 Sep 2011 13:56:04 -0400

Changed in libdvdread (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
Bryce Harrington (bryce) wrote :

Here's the patch I've uploaded to Ubuntu.

Since fixing this, I've tested the package against a few more ordinary DVDs and found them to work fine, so I'll go ahead with the SRU.

description: updated
Changed in libdvdread (Ubuntu Natty):
status: In Progress → Fix Committed
tags: added: testcase
Revision history for this message
Martin Pitt (pitti) wrote : Please test proposed package

Hello rickyrockrat, or anyone else affected,

Accepted libdvdread into natty-proposed, the package will build now and be available in a few hours. Please test and give feedback here. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

tags: added: verification-needed
Revision history for this message
rickyrockrat (rickyrockrat) wrote : Re: [Bug 852345] Re: Libdvdread misses hidden files and causes segfaults to calling programs

Martin,
I don't think I have a movie to test with (it was a rental), but I'll
post to the forum page and see if anyone else can test it.

Thanks!
Doug Springer

On 10/11/2011 01:38 AM, Martin Pitt wrote:
> Hello rickyrockrat, or anyone else affected,
>
> Accepted libdvdread into natty-proposed, the package will build now and
> be available in a few hours. Please test and give feedback here. See
> https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to
> enable and use -proposed. Thank you in advance!
>
> ** Tags added: verification-needed
>

Revision history for this message
nitrogen (i-am-nitrogen) wrote :

The latest libdvdread from natty-proposed allows VLC to play the disc in question, and lsdvd to parse it (I reported bug #859284).

Martin Pitt (pitti)
tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package libdvdread - 4.1.3-10ubuntu3.1

---------------
libdvdread (4.1.3-10ubuntu3.1) natty-proposed; urgency=low

  * debian/patches/101-fix-msb-unicode.patch: Fixes unicode issue encountered
    when playing DVDs with newer protection. (LP: #852345)
 -- Robert BARABAS <dc@0xdc.org> Sun, 18 Sep 2011 13:56:04 -0400

Changed in libdvdread (Ubuntu Natty):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.