Fix r9734 - reading content outside of the first cluster of directory

git-svn-id: svn://kolibrios.org@9737 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Marat Zakiyanov 2022-03-12 14:30:52 +00:00
parent 23097ce0e6
commit fcc5dc0546

View File

@ -364,14 +364,17 @@ exFAT_get_name:
ret ret
;-------------------------------------- ;--------------------------------------
.file_directory_entry: .file_directory_entry:
; DEBUGF 1, "K : exFAT_get_name 0x85\n"
movzx eax, byte [edi+1] ; Number of Secondary directory entries movzx eax, byte [edi+1] ; Number of Secondary directory entries
dec eax dec eax
mov [ebp+exFAT.secondary_dir_entry], eax mov [ebp+exFAT.secondary_dir_entry], eax
; DEBUGF 1, "K : exFAT_get_name 0x85 SDE: %x\n", eax
lea esi, [ebp+exFAT.file_dir_entry] lea esi, [ebp+exFAT.file_dir_entry]
; DEBUGF 1, "K : exFAT.file_dir_entry ESI: %x [ESI]: %x\n", esi, [esi] ; DEBUGF 1, "K : exFAT.file_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
jmp @f jmp @f
;-------------------------------------- ;--------------------------------------
.stream_extension_directory_entry: .stream_extension_directory_entry:
; DEBUGF 1, "K : exFAT_get_name 0xC0\n"
lea esi, [ebp+exFAT.str_ext_dir_entry] lea esi, [ebp+exFAT.str_ext_dir_entry]
; DEBUGF 1, "K : exFAT.str_ext_dir_entry ESI: %x [ESI]: %x\n", esi, [esi] ; DEBUGF 1, "K : exFAT.str_ext_dir_entry ESI: %x [ESI]: %x\n", esi, [esi]
@@: @@:
@ -393,6 +396,7 @@ exFAT_get_name:
jmp .no jmp .no
;-------------------------------------- ;--------------------------------------
.longname: .longname:
; DEBUGF 1, "K : exFAT_get_name 0xC1\n"
; push ebp ; push ebp
; mov ebp,[esp+12+8+4+4+7*4+262*2+4+4] ; mov ebp,[esp+12+8+4+4+7*4+262*2+4+4]
; DEBUGF 1, "K : exFAT_get_name.longname 0 Input FS EBP:%x\n", ebp ; DEBUGF 1, "K : exFAT_get_name.longname 0 Input FS EBP:%x\n", ebp
@ -435,15 +439,18 @@ exFAT_get_name:
mov [ebp+exFAT.secondary_dir_entry], eax mov [ebp+exFAT.secondary_dir_entry], eax
jz @f jz @f
add esi, 30 add esi, 30
; DEBUGF 1, "K : exFAT_get_name 0xC1 CONT\n"
jmp .no jmp .no
; test ax, ax ; test ax, ax
; jnz .no ; if this is not first entry, more processing required ; jnz .no ; if this is not first entry, more processing required
@@: @@:
; mov esi, [ebp+exFAT.LFN_reserve_place] ; mov esi, [ebp+exFAT.LFN_reserve_place]
; DEBUGF 1, "K : exFAT_get_name.longname END \n" ; DEBUGF 1, "K : exFAT_get_name.longname END \n"
; DEBUGF 1, "K : exFAT_get_name 0xC1 END\n"
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
exFAT_entry_to_bdfe: exFAT_entry_to_bdfe:
; DEBUGF 1, "K : exFAT_ReadFolder exFAT_entry_to_bdfe \n"
; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi ; convert FAT entry at edi to BDFE (block of data of folder entry) at esi, advance esi
mov eax, [ebp-4] mov eax, [ebp-4]
mov [esi+4], eax ; cp866/UNICODE name mov [esi+4], eax ; cp866/UNICODE name
@ -587,6 +594,9 @@ exFAT_hd_find_lfn:
push 0 push 0
push exFAT_notroot_first ; 0 ; fat1x_root_first push exFAT_notroot_first ; 0 ; fat1x_root_first
push exFAT_notroot_next ; 0 ; fat1x_root_next push exFAT_notroot_next ; 0 ; fat1x_root_next
xor eax, eax
mov [ebp+exFAT.General_Sec_Flags], eax
mov dword [ebp+exFAT.valid_data_length], 0xffffffff ; for ROOT
mov eax, [ebp+exFAT.ROOT_CLUSTER] mov eax, [ebp+exFAT.ROOT_CLUSTER]
; mov [ebp+exFAT.secondary_dir_entry], dword 1 ; mov [ebp+exFAT.secondary_dir_entry], dword 1
; cmp [ebp+FAT.fs_type], 32 ; cmp [ebp+FAT.fs_type], 32
@ -622,6 +632,17 @@ exFAT_hd_find_lfn:
; mov eax, [edi+20-2] ; mov eax, [edi+20-2]
; mov ax, [edi+26] ; cluster ; mov ax, [edi+26] ; cluster
lea eax, [ebp+exFAT.str_ext_dir_entry] lea eax, [ebp+exFAT.str_ext_dir_entry]
push eax
movzx eax, byte [eax+1]
mov [ebp+exFAT.General_Sec_Flags], eax
; DEBUGF 1, "K : exFAT General_Sec_Flags %x\n", eax
mov eax, [esp]
mov eax, [eax+8] ; LOW dword of Valid data length - WARNING!!! late rewrite
mov [ebp+exFAT.valid_data_length], eax
; DEBUGF 1, "K : exFAT.valid_data_length 1 %x\n", eax
pop eax
mov eax, [eax+20] ; cluster mov eax, [eax+20] ; cluster
;.fat32: ;.fat32:
@@: @@:
@ -667,13 +688,14 @@ exFAT_find_lfn:
; CF=1 -> file not found, eax = error code ; CF=1 -> file not found, eax = error code
mov [ebp+exFAT.secondary_dir_entry], dword 1 mov [ebp+exFAT.secondary_dir_entry], dword 1
lea eax, [esp+12] lea eax, [esp+12]
call dword [eax-4] call dword [eax-4] ; exFAT_notroot_first
jc .reterr jc .reterr
sub esp, 262*2 ; reserve place for LFN sub esp, 262*2 ; reserve place for LFN
; lea eax, [esp] ; lea eax, [esp]
mov eax, esp mov eax, esp
mov [ebp+exFAT.LFN_reserve_place], eax mov [ebp+exFAT.LFN_reserve_place], eax
mov [ebp+exFAT.path_in_UTF8], esi mov [ebp+exFAT.path_in_UTF8], esi
; DEBUGF 1, "K : exFAT_find_lfn Path: %s\n", esi
.l1: .l1:
; push esi ; push esi
; lea esi, [esp+4] ; lea esi, [esp+4]
@ -728,7 +750,7 @@ exFAT_find_lfn:
cmp [ebp+exFAT.secondary_dir_entry], eax cmp [ebp+exFAT.secondary_dir_entry], eax
jz @f jz @f
lea eax, [esp+12] lea eax, [esp+12]
call dword[eax-8] call dword[eax-8] ; exFAT_notroot_next
jc .reterr jc .reterr
@@: @@:
; DEBUGF 1, "K : exFAT_find_lfn.OK \n" ; DEBUGF 1, "K : exFAT_find_lfn.OK \n"
@ -748,8 +770,14 @@ exFAT_find_lfn:
.no: .no:
; DEBUGF 1, "K : exFAT_find_lfn.no \n" ; DEBUGF 1, "K : exFAT_find_lfn.no \n"
lea eax, [esp+262*2+12] lea eax, [esp+262*2+12]
call dword[eax-8] ; DEBUGF 1, "K : exFAT General_Sec_Flags %x\n", [ebp+exFAT.General_Sec_Flags]
; DEBUGF 1, "K : exFAT.valid_data_length 2 %x\n", [ebp+exFAT.valid_data_length]
cmp [ebp+exFAT.valid_data_length], 0
jbe @f
call dword[eax-8] ; exFAT_notroot_next
jnc .l1 jnc .l1
@@:
add esp, 262*2 add esp, 262*2
.reterr: .reterr:
; DEBUGF 1, "K : exFAT_find_lfn.reterr \n" ; DEBUGF 1, "K : exFAT_find_lfn.reterr \n"
@ -884,7 +912,7 @@ exFAT_ReadFile:
; Bits 2 7 : Reserved ; Bits 2 7 : Reserved
; test byte [edi+1], 11b ; test byte [edi+1], 11b
; pop edi ; pop edi
test byte [ebp+exFAT.General_Sec_Flags], 11b test byte [ebp+exFAT.General_Sec_Flags], 10b
jz .get_FAT_1 jz .get_FAT_1
inc eax inc eax
jmp .continue_1 jmp .continue_1
@ -1075,7 +1103,7 @@ exFAT_ReadFile:
; Bits 2 7 : Reserved ; Bits 2 7 : Reserved
; test byte [edi+1], 11b ; test byte [edi+1], 11b
; pop edi ; pop edi
test byte [ebp+exFAT.General_Sec_Flags], 11b test byte [ebp+exFAT.General_Sec_Flags], 10b
jz .get_FAT jz .get_FAT
inc eax ; inc cluster inc eax ; inc cluster
jmp .continue jmp .continue
@ -1293,6 +1321,7 @@ exFAT_ReadFolder:
call exFAT_lock call exFAT_lock
xor eax, eax xor eax, eax
mov [ebp+exFAT.General_Sec_Flags], eax mov [ebp+exFAT.General_Sec_Flags], eax
; DEBUGF 1, "K : exFAT_ReadFolder General_Sec_Flags 1 %x\n", eax
mov eax, [ebp+exFAT.ROOT_CLUSTER] mov eax, [ebp+exFAT.ROOT_CLUSTER]
; DEBUGF 1, "K : exFAT.ROOT_CLUSTER: %x\n", eax ; DEBUGF 1, "K : exFAT.ROOT_CLUSTER: %x\n", eax
cmp byte [esi], 0 cmp byte [esi], 0
@ -1323,6 +1352,7 @@ exFAT_ReadFolder:
push eax push eax
movzx eax, byte [eax+1] movzx eax, byte [eax+1]
mov [ebp+exFAT.General_Sec_Flags], eax mov [ebp+exFAT.General_Sec_Flags], eax
; DEBUGF 1, "K : exFAT_ReadFolder General_Sec_Flags 2 %x\n", eax
mov eax, [esp] mov eax, [esp]
mov eax, [eax+8] ; LOW dword of Valid data length - WARNING!!! late rewrite mov eax, [eax+8] ; LOW dword of Valid data length - WARNING!!! late rewrite
mov [ebp+exFAT.valid_data_length], eax mov [ebp+exFAT.valid_data_length], eax
@ -1439,6 +1469,7 @@ exFAT_ReadFolder:
jc .l2 jc .l2
; cmp byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT ; cmp byte [edi], 0xC1 ; File Name Extension Directory Entry of ExFAT
; jnz .do_bdfe ; jnz .do_bdfe
; DEBUGF 1, "K : exFAT_ReadFolder CMP SDE\n"
xor eax, eax xor eax, eax
cmp [ebp+exFAT.secondary_dir_entry], eax cmp [ebp+exFAT.secondary_dir_entry], eax
jz .do_bdfe jz .do_bdfe
@ -1447,6 +1478,7 @@ exFAT_ReadFolder:
; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe EDI:%x [EDI]:%x NAME:%s\n", edi, [edi], edi ; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe EDI:%x [EDI]:%x NAME:%s\n", edi, [edi], edi
cmp edi, ebx cmp edi, ebx
jb .do_bdfe jb .do_bdfe
; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe EDI after\n", edi, ebx
pop eax pop eax
inc eax inc eax
dec dword [esp+4] dec dword [esp+4]
@ -1462,7 +1494,7 @@ exFAT_ReadFolder:
; 1 No; The Contiguous Cluster are allocated to this file/directory; ; 1 No; The Contiguous Cluster are allocated to this file/directory;
; This improves the File read performance ; This improves the File read performance
; Bits 2 7 : Reserved ; Bits 2 7 : Reserved
test byte [ebp+exFAT.General_Sec_Flags], 11b test byte [ebp+exFAT.General_Sec_Flags], 10b
jz .get_FAT_1 jz .get_FAT_1
inc eax inc eax
jmp .continue_1 jmp .continue_1
@ -1474,6 +1506,7 @@ exFAT_ReadFolder:
cmp eax, 2 cmp eax, 2
jb .done jb .done
.continue_1: .continue_1:
; DEBUGF 1, "K : exFAT_ReadFolder.continue_1\n"
cmp eax, [ebp+exFAT.fatRESERVED] cmp eax, [ebp+exFAT.fatRESERVED]
jae .done jae .done
push eax push eax
@ -1505,6 +1538,7 @@ exFAT_ReadFolder:
; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe ECX: %x\n", ecx ; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe ECX: %x\n", ecx
dec ecx dec ecx
js .l2 js .l2
; DEBUGF 1, "K : exFAT_ReadFolder.do_bdfe 2 \n"
inc dword [edx+4] ; new file block copied inc dword [edx+4] ; new file block copied
push esi edi push esi edi
mov esi, [ebp+exFAT.points_to_BDFE] mov esi, [ebp+exFAT.points_to_BDFE]
@ -1545,7 +1579,7 @@ exFAT_ReadFolder:
; 1 No; The Contiguous Cluster are allocated to this file/directory; ; 1 No; The Contiguous Cluster are allocated to this file/directory;
; This improves the File read performance ; This improves the File read performance
; Bits 2 7 : Reserved ; Bits 2 7 : Reserved
test byte [ebp+exFAT.General_Sec_Flags], 11b test byte [ebp+exFAT.General_Sec_Flags], 10b
jz .get_FAT jz .get_FAT
inc eax inc eax
jmp .continue jmp .continue
@ -1557,8 +1591,10 @@ exFAT_ReadFolder:
cmp eax, 2 cmp eax, 2
jb .done jb .done
.continue: .continue:
; DEBUGF 1, "K : exFAT_ReadFolder.continue \n"
cmp eax, [ebp+exFAT.fatRESERVED] cmp eax, [ebp+exFAT.fatRESERVED]
jae .done jae .done
; DEBUGF 1, "K : exFAT_ReadFolder.continue after\n"
push eax push eax
mov eax, [ebp+exFAT.SECTORS_PER_CLUSTER] mov eax, [ebp+exFAT.SECTORS_PER_CLUSTER]
mov [esp+8], eax mov [esp+8], eax
@ -1621,6 +1657,13 @@ exFAT_ReadFolder:
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
exFAT_GetFileInfo: exFAT_GetFileInfo:
; DEBUGF 1, "K : exFAT_GetFileInfo \n" ; DEBUGF 1, "K : exFAT_GetFileInfo \n"
; DEBUGF 1, "K : exFAT F70 +00: %x\n", [ebx]
; DEBUGF 1, "K : exFAT F70 +04: %x\n", [ebx+4]
; DEBUGF 1, "K : exFAT F70 +08: %x\n", [ebx+8]
; DEBUGF 1, "K : exFAT F70 +12: %x\n", [ebx+12]
; DEBUGF 1, "K : exFAT F70 +16: %x\n", [ebx+16]
; DEBUGF 1, "K : exFAT F70 +20: %x\n", [ebx+20]
; DEBUGF 1, "K : exFAT Path: %s\n", esi
cmp byte [esi], 0 cmp byte [esi], 0
jz .volume jz .volume
call exFAT_lock call exFAT_lock
@ -1679,13 +1722,14 @@ exFAT_GetFileInfo:
ret ret
;------------------------------------------------------------------------------ ;------------------------------------------------------------------------------
exFAT_notroot_next: exFAT_notroot_next:
; DEBUGF 1, "K : exFAT_notroot_next \n" ; DEBUGF 1, "K : exFAT_notroot_next\n"
push ecx push ecx
lea ecx, [ebp+exFAT.buffer+0x200-0x20] lea ecx, [ebp+exFAT.buffer+0x200-0x20]
cmp edi, ecx cmp edi, ecx
jae exFAT_notroot_next_sector jae exFAT_notroot_next_sector
add edi, 0x20 add edi, 0x20
@@: @@:
; DEBUGF 1, "K : exFAT_notroot_next.ret\n"
pop ecx pop ecx
ret ret
@ -1698,6 +1742,7 @@ exFAT_notroot_next:
; call exFAT_notroot_end_write ; call exFAT_notroot_end_write
; pop eax ; pop eax
exFAT_notroot_next_sector: exFAT_notroot_next_sector:
; DEBUGF 1, "K : exFAT_notroot_next_sector\n"
push [ebp+exFAT.longname_sec2] push [ebp+exFAT.longname_sec2]
pop [ebp+exFAT.longname_sec1] pop [ebp+exFAT.longname_sec1]
push eax push eax
@ -1714,6 +1759,7 @@ exFAT_notroot_next_sector:
jmp @f jmp @f
exFAT_notroot_next_err: exFAT_notroot_next_err:
; DEBUGF 1, "K : exFAT_notroot_next_err\n"
; dec ecx ; dec ecx
pop ecx pop ecx
; js .1 ; js .1
@ -1723,11 +1769,12 @@ exFAT_notroot_next_err:
ret ret
exFAT_notroot_next_cluster: exFAT_notroot_next_cluster:
; DEBUGF 1, "K : exFAT_notroot_next_cluster\n"
push eax push eax
mov eax, [eax] mov eax, [eax]
push edi ; push edi
lea edi, [ebp+exFAT.str_ext_dir_entry] ; lea edi, [ebp+exFAT.str_ext_dir_entry]
; Check - General Secondary Flags ; Check - General Secondary Flags
; Bit 0 : Allocation possible ; Bit 0 : Allocation possible
; 0 No cluster allocated; 1 cluster allocation is possible ; 0 No cluster allocated; 1 cluster allocation is possible
@ -1736,8 +1783,15 @@ exFAT_notroot_next_cluster:
; 1 No; The Contiguous Cluster are allocated to this file/directory; ; 1 No; The Contiguous Cluster are allocated to this file/directory;
; This improves the File read performance ; This improves the File read performance
; Bits 2 7 : Reserved ; Bits 2 7 : Reserved
test byte [edi+1], 11b ; push eax
pop edi ; movzx eax, byte [edi+1]
; DEBUGF 1, "K : exFAT_notroot_next_cluster GSF 1:%x\n", eax
; movzx eax, byte [ebp+exFAT.General_Sec_Flags]
; DEBUGF 1, "K : exFAT_notroot_next_cluster GSF 2:%x\n", eax
; pop eax
; test byte [edi+1], 10b ;11b
; pop edi
test byte [ebp+exFAT.General_Sec_Flags], 10b
jz .get_FAT jz .get_FAT
inc eax inc eax
jmp .continue jmp .continue
@ -1756,23 +1810,26 @@ exFAT_notroot_next_cluster:
@@: @@:
pop ecx pop ecx
exFAT_notroot_first: exFAT_notroot_first:
; DEBUGF 1, "K : exFAT_notroot_first \n" ; DEBUGF 1, "K : exFAT_notroot_first\n"
; DEBUGF 1, "K : exFAT_notroot_first.exFAT_get_sector In EAX:%x\n", eax ; DEBUGF 1, "K : exFAT_notroot_first.exFAT_get_sector In EAX:%x\n", eax
call exFAT_get_sector call exFAT_get_sector
; DEBUGF 1, "K : exFAT_notroot_first.exFAT_get_sector Out EAX:%x\n", eax ; DEBUGF 1, "K : exFAT_notroot_first.exFAT_get_sector Out EAX:%x\n", eax
push ebx push ebx
lea edi, [ebp+exFAT.buffer] lea edi, [ebp+exFAT.buffer]
mov ebx, edi mov ebx, edi
sub [ebp+exFAT.valid_data_length], 512
call fs_read32_sys call fs_read32_sys
pop ebx pop ebx
test eax, eax test eax, eax
jz .ret ; CF=0 jz .ret ; CF=0
push ecx push ecx
.deverr: .deverr:
; DEBUGF 1, "K : exFAT_notroot_first.deverr\n"
pop ecx pop ecx
mov eax, ERROR_DEVICE mov eax, ERROR_DEVICE
stc stc
.ret: .ret:
; DEBUGF 1, "K : exFAT_notroot_first.ret\n"
ret ret
;fat_notroot_begin_write: ;fat_notroot_begin_write:
@ -1790,6 +1847,7 @@ exFAT_notroot_first:
; ret ; ret
;-------------------------------------- ;--------------------------------------
exFAT_get_sector: exFAT_get_sector:
; DEBUGF 1, "K : exFAT_get_sector\n"
push ecx push ecx
mov ecx, [eax] mov ecx, [eax]
; DEBUGF 1, "K : exFAT_get_sector In [EAX]:%x [EAX+4]:%x\n", ecx, [eax+4] ; DEBUGF 1, "K : exFAT_get_sector In [EAX]:%x [EAX+4]:%x\n", ecx, [eax+4]