File import of zipped PDF does not detect filetype correctly

Bug #1318995 reported by Matt Gibson
32
This bug affects 9 people
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Medium
Robert Lyon
1.7
Fix Released
Medium
Robert Lyon
1.8
Fix Released
Medium
Robert Lyon
1.9
Fix Released
Medium
Robert Lyon

Bug Description

In Mahara 1.9.0

After building a portfolio export button for the Moodle certificate module using MNet, I found that the PDF file was getting saved with the mimetype set to application/x-director. This turned out to be because the import process does not correctly pass through the file extension.

In import/file/lib.php, around line 108 in the add_artefacts() function is a call to ArtefactTypeFile::save_file(). The $data does not include and $oldextension attribute, but this is expected later on around line 947 of artefact/file/lib.php in the new_file() function. The following line throws an error:

$data->guess = file_mime_type($path, "foo.{$data->oldextension}");

And then file_mime_type() fails because it doesn't know what the extension is.

To fix it, the following chunk of code works nicely:

        if (isset($data->oldextension)) {
            $originalfilename = "foo.{$data->oldextension}";
        } else {
            $originalfilename = false;
        }
        $data->guess = file_mime_type($path, $originalfilename);

This causes the original filename to be read from the file object.

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/3384

Robert Lyon (robertl-9)
Changed in mahara:
milestone: none → 1.10.0
assignee: nobody → Robert Lyon (robertl-9)
importance: Undecided → Medium
status: New → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/3384
Committed: http://gitorious.org/mahara/mahara/commit/726839042fa61cf8dd017a1971c41d371ab91338
Submitter: Son Nguyen (<email address hidden>)
Branch: master

commit 726839042fa61cf8dd017a1971c41d371ab91338
Author: Robert Lyon <email address hidden>
Date: Tue May 27 12:49:53 2014 +1200

Passing in oldextension variable when doing import or zip extraction

Bug 1318995

Change-Id: I3ab1c23cb5fcd188436224508cf5b9127e7fb290
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Peter Friesen (peter-friesen) wrote :

The solution proposed here also seems to resolve the issue I report in Bug 1329807 (https://bugs.launchpad.net/mahara/+bug/1329807)

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Hello Robert,

Can you please backport this to 1.9?

Thank you
Kristina

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "1.9_STABLE" branch: https://reviews.mahara.org/3650

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "1.8_STABLE" branch: https://reviews.mahara.org/3651

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "1.7_STABLE" branch: https://reviews.mahara.org/3652

Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "master" branch: https://reviews.mahara.org/3720

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/3650
Committed: http://gitorious.org/mahara/mahara/commit/feccff4035f573fc96ce0ffcefb48113f08fc4fc
Submitter: Son Nguyen (<email address hidden>)
Branch: 1.9_STABLE

commit feccff4035f573fc96ce0ffcefb48113f08fc4fc
Author: Robert Lyon <email address hidden>
Date: Tue May 27 12:49:53 2014 +1200

Passing in oldextension variable when doing import or zip extraction

Bug 1318995

Change-Id: I3ab1c23cb5fcd188436224508cf5b9127e7fb290
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/3720
Committed: http://gitorious.org/mahara/mahara/commit/99e9850ecad9bed51b9b93d7e92f706c33f97c39
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 99e9850ecad9bed51b9b93d7e92f706c33f97c39
Author: Robert Lyon <email address hidden>
Date: Thu Sep 25 07:58:37 2014 +1200

Getting old extension when unzipping a .tar file (Bug #1318995)

Change-Id: Ib77c0970d6f1e0d3248b58744349b49447d7c413
Signed-off-by: Robert Lyon <email address hidden>

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "1.8_STABLE" branch: https://reviews.mahara.org/3758

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "1.7_STABLE" branch: https://reviews.mahara.org/3759

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/3758
Committed: http://gitorious.org/mahara/mahara/commit/3304c9ac9b99b75e2d88deb9de33cb859ce2e121
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.8_STABLE

commit 3304c9ac9b99b75e2d88deb9de33cb859ce2e121
Author: Robert Lyon <email address hidden>
Date: Thu Sep 25 07:58:37 2014 +1200

Getting old extension when unzipping a .tar file (Bug #1318995)

Change-Id: Ib77c0970d6f1e0d3248b58744349b49447d7c413
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/3759
Committed: http://gitorious.org/mahara/mahara/commit/aa399885d7efa096467435b40bb599963c694a7d
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.7_STABLE

commit aa399885d7efa096467435b40bb599963c694a7d
Author: Robert Lyon <email address hidden>
Date: Thu Sep 25 07:58:37 2014 +1200

Getting old extension when unzipping a .tar file (Bug #1318995)

Change-Id: Ib77c0970d6f1e0d3248b58744349b49447d7c413
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Jinelle Foley-Barnes (jinelleb) wrote :

Hi,

I wish to test this and try convert to a Behat test also. Could I please have a test case?

This is proving quite complicated.

Thank you,

Jinelle

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "1.10_STABLE" branch: https://reviews.mahara.org/3774

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/3774
Committed: http://gitorious.org/mahara/mahara/commit/61e2e7941dede54fca063ca2942b3d925186e889
Submitter: Robert Lyon (<email address hidden>)
Branch: 1.10_STABLE

commit 61e2e7941dede54fca063ca2942b3d925186e889
Author: Robert Lyon <email address hidden>
Date: Thu Sep 25 07:58:37 2014 +1200

Getting old extension when unzipping a .tar file (Bug #1318995)

Change-Id: Ib77c0970d6f1e0d3248b58744349b49447d7c413
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/3652
Committed: http://gitorious.org/mahara/mahara/commit/27fd7d1f560ca818a2f583cc8a4a17176858383f
Submitter: Son Nguyen (<email address hidden>)
Branch: 1.7_STABLE

commit 27fd7d1f560ca818a2f583cc8a4a17176858383f
Author: Robert Lyon <email address hidden>
Date: Tue May 27 12:49:53 2014 +1200

Passing in oldextension variable when doing import or zip extraction

Bug 1318995

Change-Id: I3ab1c23cb5fcd188436224508cf5b9127e7fb290
Signed-off-by: Robert Lyon <email address hidden>

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/3651
Committed: http://gitorious.org/mahara/mahara/commit/9fd0310e7722c39df02b94f7008497e1afd9bb95
Submitter: Son Nguyen (<email address hidden>)
Branch: 1.8_STABLE

commit 9fd0310e7722c39df02b94f7008497e1afd9bb95
Author: Robert Lyon <email address hidden>
Date: Tue May 27 12:49:53 2014 +1200

Passing in oldextension variable when doing import or zip extraction

Bug 1318995

Change-Id: I3ab1c23cb5fcd188436224508cf5b9127e7fb290
Signed-off-by: Robert Lyon <email address hidden>

Aaron Wells (u-aaronw)
Changed in mahara:
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.