@@ -1065,26 +1065,39 @@ int ocfs2_find_entry(const char *name, int namelen,
10651065{
10661066 struct buffer_head * bh ;
10671067 struct ocfs2_dir_entry * res_dir = NULL ;
1068+ int ret = 0 ;
10681069
10691070 if (ocfs2_dir_indexed (dir ))
10701071 return ocfs2_find_entry_dx (name , namelen , dir , lookup );
10711072
1073+ if (unlikely (i_size_read (dir ) <= 0 )) {
1074+ ret = - EFSCORRUPTED ;
1075+ mlog_errno (ret );
1076+ goto out ;
1077+ }
10721078 /*
10731079 * The unindexed dir code only uses part of the lookup
10741080 * structure, so there's no reason to push it down further
10751081 * than this.
10761082 */
1077- if (OCFS2_I (dir )-> ip_dyn_features & OCFS2_INLINE_DATA_FL )
1083+ if (OCFS2_I (dir )-> ip_dyn_features & OCFS2_INLINE_DATA_FL ) {
1084+ if (unlikely (i_size_read (dir ) > dir -> i_sb -> s_blocksize )) {
1085+ ret = - EFSCORRUPTED ;
1086+ mlog_errno (ret );
1087+ goto out ;
1088+ }
10781089 bh = ocfs2_find_entry_id (name , namelen , dir , & res_dir );
1079- else
1090+ } else {
10801091 bh = ocfs2_find_entry_el (name , namelen , dir , & res_dir );
1092+ }
10811093
10821094 if (bh == NULL )
10831095 return - ENOENT ;
10841096
10851097 lookup -> dl_leaf_bh = bh ;
10861098 lookup -> dl_entry = res_dir ;
1087- return 0 ;
1099+ out :
1100+ return ret ;
10881101}
10891102
10901103/*
@@ -2010,6 +2023,7 @@ int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name,
20102023 *
20112024 * Return 0 if the name does not exist
20122025 * Return -EEXIST if the directory contains the name
2026+ * Return -EFSCORRUPTED if found corruption
20132027 *
20142028 * Callers should have i_rwsem + a cluster lock on dir
20152029 */
@@ -2023,9 +2037,12 @@ int ocfs2_check_dir_for_entry(struct inode *dir,
20232037 trace_ocfs2_check_dir_for_entry (
20242038 (unsigned long long )OCFS2_I (dir )-> ip_blkno , namelen , name );
20252039
2026- if (ocfs2_find_entry (name , namelen , dir , & lookup ) == 0 ) {
2040+ ret = ocfs2_find_entry (name , namelen , dir , & lookup );
2041+ if (ret == 0 ) {
20272042 ret = - EEXIST ;
20282043 mlog_errno (ret );
2044+ } else if (ret == - ENOENT ) {
2045+ ret = 0 ;
20292046 }
20302047
20312048 ocfs2_free_dir_lookup_result (& lookup );
0 commit comments