Module: wine Branch: master Commit: d7bbe884ef29215f4db2027f450fb959314f5383 URL: https://gitlab.winehq.org/wine/wine/-/commit/d7bbe884ef29215f4db2027f450fb95...
Author: Zebediah Figura zfigura@codeweavers.com Date: Sat Mar 2 15:23:56 2024 -0600
msi: Store component cost in 512-byte units.
This avoids overflow when component costs exceed 4 GB.
---
dlls/msi/action.c | 14 +++++++------- dlls/msi/install.c | 3 +-- dlls/msi/msi.c | 4 ++-- dlls/msi/msipriv.h | 3 ++- dlls/msi/tests/package.c | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/dlls/msi/action.c b/dlls/msi/action.c index 20da818e686..06f399223f4 100644 --- a/dlls/msi/action.c +++ b/dlls/msi/action.c @@ -2070,7 +2070,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package )
if (msi_get_file_attributes( package, file->TargetPath ) == INVALID_FILE_ATTRIBUTES) { - comp->Cost += file->FileSize; + comp->cost += cost_from_size( file->FileSize ); continue; } file_size = msi_get_disk_file_size( package, file->TargetPath ); @@ -2082,7 +2082,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package ) { if (msi_compare_file_versions( file_version, file->Version ) < 0) { - comp->Cost += file->FileSize - file_size; + comp->cost += cost_from_size( file->FileSize - file_size ); } free( file_version ); continue; @@ -2091,7 +2091,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package ) { if (msi_compare_font_versions( font_version, file->Version ) < 0) { - comp->Cost += file->FileSize - file_size; + comp->cost += cost_from_size( file->FileSize - file_size ); } free( font_version ); continue; @@ -2099,7 +2099,7 @@ static UINT calculate_file_cost( MSIPACKAGE *package ) } if (file_size != file->FileSize) { - comp->Cost += file->FileSize - file_size; + comp->cost += cost_from_size( file->FileSize - file_size ); } }
@@ -2217,7 +2217,7 @@ static ULONGLONG get_volume_space_required( MSIPACKAGE *package )
LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry ) { - if (comp->Action == INSTALLSTATE_LOCAL) ret += comp->Cost; + if (comp->Action == INSTALLSTATE_LOCAL) ret += comp->cost; } return ret; } @@ -2292,10 +2292,10 @@ static UINT ACTION_CostFinalize(MSIPACKAGE *package) msi_set_property( package->db, L"PrimaryVolumeSpaceAvailable", buf, -1 ); } required = get_volume_space_required( package ); - swprintf( buf, ARRAY_SIZE(buf), L"%lu", required / 512 ); + swprintf( buf, ARRAY_SIZE(buf), L"%lu", required ); msi_set_property( package->db, L"PrimaryVolumeSpaceRequired", buf, -1 );
- swprintf( buf, ARRAY_SIZE(buf), L"%lu", (free.QuadPart - required) / 512 ); + swprintf( buf, ARRAY_SIZE(buf), L"%lu", (free.QuadPart / 512) - required ); msi_set_property( package->db, L"PrimaryVolumeSpaceRemaining", buf, -1 ); msi_set_property( package->db, L"PrimaryVolumePath", primary_folder, 2 ); } diff --git a/dlls/msi/install.c b/dlls/msi/install.c index 609a3016eaa..f4db3b510f1 100644 --- a/dlls/msi/install.c +++ b/dlls/msi/install.c @@ -1147,7 +1147,7 @@ static INT feature_cost( MSIFEATURE *feature )
LIST_FOR_EACH_ENTRY( cl, &feature->Components, ComponentList, entry ) { - cost += cl->component->Cost; + cost += cl->component->cost; } return cost; } @@ -1197,7 +1197,6 @@ UINT MSI_GetFeatureCost( MSIPACKAGE *package, MSIFEATURE *feature, MSICOSTTREE t break; }
- *cost /= 512; return ERROR_SUCCESS; }
diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 611399a8fb0..2c0f3aa50f5 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -2028,7 +2028,7 @@ UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, const WCHAR *component, DW GetWindowsDirectoryW( path, MAX_PATH ); if (component && component[0]) { - if (msi_is_global_assembly( comp )) *temp = comp->Cost; + if (msi_is_global_assembly( comp )) *temp = comp->cost; if (!comp->Enabled || !comp->KeyPath) { *cost = 0; @@ -2037,7 +2037,7 @@ UINT WINAPI MsiEnumComponentCostsW( MSIHANDLE handle, const WCHAR *component, DW } else if ((file = msi_get_loaded_file( package, comp->KeyPath ))) { - *cost = cost_from_size( comp->Cost ); + *cost = comp->cost; *buflen = set_drive( drive, file->TargetPath[0] ); r = ERROR_SUCCESS; } diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index 588aa9a7487..b7bc1e7b067 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -532,7 +532,8 @@ typedef struct tagMSICOMPONENT INSTALLSTATE Action; BOOL ForceLocalState; BOOL Enabled; - INT Cost; + /* Cost is in 512-byte units, as returned from MsiEnumComponentCosts() et al. */ + int cost; INT RefCount; LPWSTR FullKeypath; LPWSTR AdvertiseString; diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c index 9257a835891..228fd91ef43 100644 --- a/dlls/msi/tests/package.c +++ b/dlls/msi/tests/package.c @@ -8607,7 +8607,7 @@ static void test_costs(void) ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r ); ok( len == 2, "expected len == 2, got %lu\n", len ); ok( drive[0], "expected a drive\n" ); - todo_wine ok( cost == 12000024, "got %d\n", cost ); + ok( cost == 12000024, "got %d\n", cost ); ok( !temp, "expected temp == 0, got %d\n", temp );
len = sizeof(drive); @@ -8651,7 +8651,7 @@ static void test_costs(void) cost = 0xdead; r = MsiGetFeatureCostA( hpkg, "one", MSICOSTTREE_SELFONLY, INSTALLSTATE_LOCAL, &cost ); ok( !r, "got %u\n", r); - todo_wine ok( cost == 12000024, "got %d\n", cost ); + ok( cost == 12000024, "got %d\n", cost );
MsiCloseHandle( hpkg ); error: