Author: stefan2 Date: Thu May 25 16:03:34 2017 New Revision: 1796160 URL: http://svn.apache.org/viewvc?rev=1796160&view=rev Log: Make the FSFS format 7 metadata verification more thorough.
* subversion/libsvn_fs_fs/verify.c (compare_p2l_to_rev): Verify item types to the degree feasible. Modified: subversion/trunk/subversion/libsvn_fs_fs/verify.c Modified: subversion/trunk/subversion/libsvn_fs_fs/verify.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/verify.c?rev=1796160&r1=1796159&r2=1796160&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_fs_fs/verify.c (original) +++ subversion/trunk/subversion/libsvn_fs_fs/verify.c Thu May 25 16:03:34 2017 @@ -673,15 +673,45 @@ compare_p2l_to_rev(svn_fs_t *fs, apr_off_t_toa(pool, offset), apr_off_t_toa(pool, entry->offset)); - /* empty sections must contain NUL bytes only */ + /* Check type <-> item dependencies. */ + + /* Entry types must be within the valid range. */ + if (entry->type >= SVN_FS_FS__ITEM_TYPE_ANY_REP) + return svn_error_createf(SVN_ERR_FS_INDEX_CORRUPTION, + NULL, + _("p2l index entry for revision r%ld" + " at offset %s contains invalid item" + " type %d"), + start, + apr_off_t_toa(pool, offset), + entry->type); + + /* There can be only one changes entry and that has a fixed type + * and item number. Its presence and parse-ability will be checked + * during later stages of the verification process. */ + if ( (entry->type == SVN_FS_FS__ITEM_TYPE_CHANGES) + != (entry->item.number == SVN_FS_FS__ITEM_INDEX_CHANGES)) + return svn_error_createf(SVN_ERR_FS_INDEX_CORRUPTION, + NULL, + _("p2l index entry for changes in" + " revision r%ld is item %ld of type" + " %d at offset %s"), + entry->item.revision, + entry->item.number, + entry->type, + apr_off_t_toa(pool, offset)); + + /* Check contents. */ if (entry->type == SVN_FS_FS__ITEM_TYPE_UNUSED) { - /* skip filler entry at the end of the p2l index */ + /* Empty sections must contain NUL bytes only. + * Beware of the filler at the end of the p2l index. */ if (entry->offset != max_offset) SVN_ERR(read_all_nul(rev_file->file, entry->size, pool)); } else { + /* Generic contents check against checksum. */ if (entry->size < STREAM_THRESHOLD) SVN_ERR(expected_buffered_checksum(rev_file->file, entry, pool));