markokr/rarfile

"Failed the read enough data" Possible temp fix?

JoeBlackSecurity opened this issue · 1 comments

I had a big issue with the dreaded "Failed the read enough data: req=X got=X" error. I am processing over 15k rars and this error came up for nearly 40% of them which prevented extracting these files. It was making me crazy because rarfile was the best implementation for my use case.
After playing around and doing lots of research, it seems this issues is in unrar and most of the variants. I was never able to understand exactly why this error comes up with some rars but not others. I suspect its due to the binary version or maybe os in which the file was created with.
After more playing around I discovered that adding a * at the end of the filename that you're trying to decompress seems to make the error just go away.

At the cmd line it would look like this:
unrar p -inul -pPassword -- 'Rar-File' 'File_location_in_rar*' Notice the * at the end of File_location_in_rar.
This actually make it work. Didnt need to alter the rest of the data at all.

As for rarfile, thats super easy. (line 1304)

        if not tmpfile or force_file:
            fn = inf.filename + "*"

This little addition made EVERYTHING work. Now I dont have a singe issue with this error in any of my 15k rars. Everything extracts perfectly. Obviously this would be better implemented with a check on error but just like this works too.

Will this work for everyone? No idea. But 5,892 rar files that were unable to be extracted before now work. Thats good odds.

I dont usually put up one of these (can you tell from my scattered thoughts and poor formatting?) but I was so surprised when it worked with such a small change, I figured I had to share since I saw this error a lot!
Hope this helps someone else out too.

I will be submitting a bug to rarlabs so maybe with this inf they can implement a fix at the binary level.

Please check out the relased rarfile v4.1 - it contains fix related to filename handling on Windows. Does it fix your problem?

If not then please reopen the issue and provide test archive that demonstrates the problem and the how your solution fixes it.

I don't want to apply such patch without testcase, it's too weird...