@@ -367,7 +367,7 @@ static umf_result_t validatePartSize(os_memory_provider_t *provider,
367367 umf_os_memory_provider_params_t * params ) {
368368 size_t page_size ;
369369 os_get_min_page_size (provider , NULL , & page_size );
370- if (ALIGN_UP (params -> part_size , page_size ) < params -> part_size ) {
370+ if (! ALIGN_UP (params -> part_size , page_size )) {
371371 LOG_ERR ("partition size (%zu) is too big, cannot align with a page "
372372 "size (%zu)" ,
373373 params -> part_size , page_size );
@@ -829,12 +829,20 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
829829 membind_t membind ;
830830 memset (& membind , 0 , sizeof (membind ));
831831
832- membind .alloc_size = ALIGN_UP (size , page_size );
832+ membind .alloc_size = ALIGN_UP_SAFE (size , page_size );
833+ if (membind .alloc_size == 0 ) {
834+ LOG_ERR ("size is too big, page align failed" );
835+ return membind ;
836+ }
833837 membind .page_size = page_size ;
834838 membind .addr = addr ;
835839 membind .pages = membind .alloc_size / membind .page_size ;
836840 if (provider -> nodeset_len == 1 ) {
837- membind .bind_size = ALIGN_UP (size , membind .page_size );
841+ membind .bind_size = ALIGN_UP_SAFE (size , membind .page_size );
842+ if (membind .bind_size == 0 ) {
843+ LOG_ERR ("size is too big, page align failed" );
844+ return membind ;
845+ }
838846 membind .bitmap = provider -> nodeset [0 ];
839847 return membind ;
840848 }
@@ -844,7 +852,12 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
844852 size_t s = util_fetch_and_add64 (& provider -> alloc_sum , size );
845853 membind .node = (s / provider -> part_size ) % provider -> nodeset_len ;
846854 membind .bitmap = provider -> nodeset [membind .node ];
847- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
855+ membind .bind_size =
856+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
857+ if (membind .bind_size == 0 ) {
858+ LOG_ERR ("size is too big, page align failed" );
859+ return membind ;
860+ }
848861 if (membind .bind_size > membind .alloc_size ) {
849862 membind .bind_size = membind .alloc_size ;
850863 }
@@ -880,7 +893,12 @@ static membind_t membindNext(os_memory_provider_t *provider,
880893 membind .node ++ ;
881894 membind .node %= provider -> nodeset_len ;
882895 membind .bitmap = provider -> nodeset [membind .node ];
883- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
896+ membind .bind_size =
897+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
898+ if (membind .bind_size == 0 ) {
899+ LOG_ERR ("part_size is too big, page align failed" );
900+ return membind ;
901+ }
884902 if (membind .bind_size > membind .alloc_size ) {
885903 membind .bind_size = membind .alloc_size ;
886904 }
0 commit comments