@@ -366,7 +366,7 @@ static umf_result_t validatePartSize(os_memory_provider_t *provider,
366366 umf_os_memory_provider_params_t * params ) {
367367 size_t page_size ;
368368 os_get_min_page_size (provider , NULL , & page_size );
369- if (ALIGN_UP (params -> part_size , page_size ) < params -> part_size ) {
369+ if (! ALIGN_UP (params -> part_size , page_size )) {
370370 LOG_ERR ("partition size (%zu) is too big, cannot align with a page "
371371 "size (%zu)" ,
372372 params -> part_size , page_size );
@@ -851,12 +851,20 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
851851 membind_t membind ;
852852 memset (& membind , 0 , sizeof (membind ));
853853
854- membind .alloc_size = ALIGN_UP (size , page_size );
854+ membind .alloc_size = ALIGN_UP_SAFE (size , page_size );
855+ if (membind .alloc_size == 0 ) {
856+ LOG_ERR ("size is too big, page align failed" );
857+ return membind ;
858+ }
855859 membind .page_size = page_size ;
856860 membind .addr = addr ;
857861 membind .pages = membind .alloc_size / membind .page_size ;
858862 if (provider -> nodeset_len == 1 ) {
859- membind .bind_size = ALIGN_UP (size , membind .page_size );
863+ membind .bind_size = ALIGN_UP_SAFE (size , membind .page_size );
864+ if (membind .bind_size == 0 ) {
865+ LOG_ERR ("size is too big, page align failed" );
866+ return membind ;
867+ }
860868 membind .bitmap = provider -> nodeset [0 ];
861869 return membind ;
862870 }
@@ -866,7 +874,12 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
866874 size_t s = util_fetch_and_add64 (& provider -> alloc_sum , size );
867875 membind .node = (s / provider -> part_size ) % provider -> nodeset_len ;
868876 membind .bitmap = provider -> nodeset [membind .node ];
869- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
877+ membind .bind_size =
878+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
879+ if (membind .bind_size == 0 ) {
880+ LOG_ERR ("size is too big, page align failed" );
881+ return membind ;
882+ }
870883 if (membind .bind_size > membind .alloc_size ) {
871884 membind .bind_size = membind .alloc_size ;
872885 }
@@ -902,7 +915,12 @@ static membind_t membindNext(os_memory_provider_t *provider,
902915 membind .node ++ ;
903916 membind .node %= provider -> nodeset_len ;
904917 membind .bitmap = provider -> nodeset [membind .node ];
905- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
918+ membind .bind_size =
919+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
920+ if (membind .bind_size == 0 ) {
921+ LOG_ERR ("part_size is too big, page align failed" );
922+ return membind ;
923+ }
906924 if (membind .bind_size > membind .alloc_size ) {
907925 membind .bind_size = membind .alloc_size ;
908926 }
0 commit comments