Merge "Add more checks for bad values to protect from corrupt files." into gingerbread