Failure to rename files in ebook editor leads to corrupted ebook

Bug #1641202 reported by m4mmon on 2016-11-11
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Undecided
Unassigned

Bug Description

calibre 2.71 64-bit / Windows 10

In some cases, an error might occur while trying to rename files in ebook editor.
If book is saved after getting the error (either it was in unsaved state, or if another modification is performed), book becomes corrupted.

1/ Open the provided sample epub file in ebook editor and try to rename a file, e.g. try to rename "start.xhtml" as something else. You get the following error message:

calibre, version 2.71.0
ERROR: Failed to rename files: Failed to rename files, click Show details for more information.

Traceback (most recent call last):
  File "site-packages\calibre\gui2\tweak_book\job.py", line 35, in run
  File "site-packages\calibre\ebooks\oeb\polish\replace.py", line 205, in rename_files
  File "site-packages\calibre\ebooks\oeb\polish\replace.py", line 125, in replace_links
  File "site-packages\calibre\ebooks\oeb\polish\container.py", line 425, in replace_links
  File "site-packages\calibre\ebooks\oeb\base.py", line 222, in rewrite_links
  File "site-packages\calibre\ebooks\oeb\polish\replace.py", line 38, in __call__
  File "site-packages\calibre\ebooks\oeb\polish\container.py", line 499, in href_to_name
  File "site-packages\calibre\ebooks\oeb\polish\container.py", line 113, in href_to_name
  File "site-packages\calibre\ebooks\oeb\polish\container.py", line 88, in abspath_to_name
  File "ntpath.py", line 528, in relpath
ValueError: path is on drive C:, start on drive E:

2/ After closing the error, make any modification, for example change some text.

3/ Save, and close the file.

4/ Reopen it: file that failed to be renamed in step #1 was in fact renamed ("on disk"), but not in the opf.

It is also possible to get the error while using the "polish books" function on the provided epub in the calibre library, with a similar error stack, but book is not corrupted.

Note: While the ebook was "error-free" before the rename operation, launching "Check Book" right after getting the error shows something is now wrong with it. So I think the error that occurs during the rename operation is not properly rolled back.

For the error to happen, I had to craft a "a" tag with some invalid (?) href (in the text.xhtml file).

The invalid URI is not detected by the "Check Book" function (flightcrew, epub check 3 and 4 detect it). I do not know if this error should be detected or not by calibre, but one thing is sure, the parsing that occurs while renaming shokes on it and blocks the rename operation, while checker does not.

Expected behavior:
- rename operation should not fail,
- if rename operation fails, ebook should not be corrupted
- may be this should be the subject of another ticked, but the initial error should have been detected, like other checker software.

Thank you.

m4mmon (m4mmon) wrote :

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers