From 78d4515e63becbe05dceba8c817bedb43ed477af Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 26 Nov 2012 15:03:43 +0530 Subject: [PATCH] Better error message when trying to extract a password protected item from a rar archive --- src/calibre/utils/unrar.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/unrar.cpp b/src/calibre/utils/unrar.cpp index e5dcb06cf4..9bcadb8e83 100644 --- a/src/calibre/utils/unrar.cpp +++ b/src/calibre/utils/unrar.cpp @@ -373,6 +373,10 @@ RAR_process_item(RARArchive *self, PyObject *args) { self->file_count++; try { if (PyObject_IsTrue(extract)) { + if ((self->archive->NewLhd.Flags & LHD_PASSWORD) != 0) { + PyErr_SetString(UNRARError, "This file is locked with a password."); + return NULL; + } self->DataIO.UnpVolume = false; self->DataIO.NextVolumeMissing=false; self->DataIO.CurUnpRead=0; @@ -421,7 +425,7 @@ RAR_process_item(RARArchive *self, PyObject *args) { bool ValidCRC = (self->archive->OldFormat && GET_UINT32(self->DataIO.UnpFileCRC)==GET_UINT32(self->archive->NewLhd.FileCRC)) || (!self->archive->OldFormat && GET_UINT32(self->DataIO.UnpFileCRC)==GET_UINT32(self->archive->NewLhd.FileCRC^0xffffffff)); if (!ValidCRC) { - PyErr_SetString(UNRARError, "Invalid CRC while extracting item"); + PyErr_SetString(UNRARError, "Invalid CRC for item"); return NULL; } // Comes from ProcessFile in dll.cpp