Page MenuHomePhabricator

Avoid reading past end of archive looking for long file name

Authored by inglorion on Apr 27 2018, 2:58 PM.



GNU-style archives store long file names separated by newlines. The
last file name is not followed by a newline. This change stops the
search for the newline at the end of the string table, which avoids
a crash.

Fixes PR37244.

Event Timeline

inglorion created this revision.Apr 27 2018, 2:58 PM
rnk edited reviewers, added: espindola, pcc; removed: rnk.Apr 27 2018, 3:26 PM
pcc added a comment.Apr 27 2018, 3:34 PM

Is it possible to construct a test case?

espindola added inline comments.Apr 27 2018, 5:21 PM

This should be an error, no?

inglorion added inline comments.Apr 28 2018, 10:53 AM

Not as I understand it. If I understand the GNU format correctly, all long filenames end in a slash, but newline is only used as a separator, meaning the last file doesn't get one. So the name is delimited either by "/\n" or by "/" <EOF>.

A test case for this would be an archive with a long file name at the end of the string table. It may have to be a specific size to tickle the problem I'm trying to fix here, to prevent MemoryBuffer or the OS from padding the archive with 0 bytes, which would avoid the problem.

Unfortunately, I have to catch a plane and I'll be gone for a week. If anyone wants to commandeer this and land it, please go ahead.

inglorion abandoned this revision.May 9 2018, 2:58 PM

We landed D46527 instead.