Skip to content

Commit

Permalink
Added extra sanity checks for uncramfs-lzma
Browse files Browse the repository at this point in the history
  • Loading branch information
devttys0 committed Dec 5, 2013
1 parent 38897b0 commit 4a04751
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/uncramfs-lzma/lzma-uncramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ void do_file(const u8* base, u32 offset, u32 size,
} else {
if(uncompress_data(base, base+offset, size, file_data) == -1)
{
printf("failed to decompress data! quitting...\n");
exit(EXIT_FAILURE);
printf("failed to decompress data\n");
}
}

Expand Down
37 changes: 33 additions & 4 deletions uncramfs_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,39 @@ then
./src/uncramfs-lzma/uncramfs-lzma "$ROOTFS" "$FSIMG.le" 2>/dev/null
if [ $? -eq 0 ]
then
# Does not exist, will not be able to re-build the file system!
MKFS="./src/uncramfs-lzma/mkcramfs-lzma"
finish
exit 0
nfiles=0
bad=0

# Check at least the first five files to make sure they didn't just extract to all zero's
for FILE in $(find "$ROOTFS")
do
if [ -f "$FILE" ]
then
echo "Checking $FILE"

if [ "$(hexdump "$FILE" | wc -l)" -lt "4" ] && [ "$(hexdump "$FILE" | head -1 | grep -v '0')" == "" ]
then
((bad=$bad+1))
else
((bad=$bad-1))
fi

((nfiles=nfiles+1))
fi

if [ "$nfiles" == "5" ]
then
break
fi
done

if [ "$bad" != "$nfiles" ]
then
# Does not exist, will not be able to re-build the file system!
MKFS="./src/uncramfs-lzma/mkcramfs-lzma"
finish
exit 0
fi
fi

./src/cramfs-2.x/cramfsck -x "$ROOTFS" "$FSIMG.le" 2>/dev/null
Expand Down

0 comments on commit 4a04751

Please sign in to comment.