@@ -834,12 +834,20 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
834834 membind_t membind ;
835835 memset (& membind , 0 , sizeof (membind ));
836836
837- membind .alloc_size = ALIGN_UP (size , page_size );
837+ membind .alloc_size = ALIGN_UP_SAFE (size , page_size );
838+ if (membind .alloc_size == 0 ) {
839+ LOG_ERR ("size is too big, page align failed" );
840+ return membind ;
841+ }
838842 membind .page_size = page_size ;
839843 membind .addr = addr ;
840844 membind .pages = membind .alloc_size / membind .page_size ;
841845 if (provider -> nodeset_len == 1 ) {
842- membind .bind_size = ALIGN_UP (size , membind .page_size );
846+ membind .bind_size = ALIGN_UP_SAFE (size , membind .page_size );
847+ if (membind .bind_size == 0 ) {
848+ LOG_ERR ("size is too big, page align failed" );
849+ return membind ;
850+ }
843851 membind .bitmap = provider -> nodeset [0 ];
844852 return membind ;
845853 }
@@ -849,7 +857,12 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
849857 size_t s = utils_fetch_and_add64 (& provider -> alloc_sum , size );
850858 membind .node = (s / provider -> part_size ) % provider -> nodeset_len ;
851859 membind .bitmap = provider -> nodeset [membind .node ];
852- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
860+ membind .bind_size =
861+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
862+ if (membind .bind_size == 0 ) {
863+ LOG_ERR ("size is too big, page align failed" );
864+ return membind ;
865+ }
853866 if (membind .bind_size > membind .alloc_size ) {
854867 membind .bind_size = membind .alloc_size ;
855868 }
@@ -885,7 +898,12 @@ static membind_t membindNext(os_memory_provider_t *provider,
885898 membind .node ++ ;
886899 membind .node %= provider -> nodeset_len ;
887900 membind .bitmap = provider -> nodeset [membind .node ];
888- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
901+ membind .bind_size =
902+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
903+ if (membind .bind_size == 0 ) {
904+ LOG_ERR ("part_size is too big, page align failed" );
905+ return membind ;
906+ }
889907 if (membind .bind_size > membind .alloc_size ) {
890908 membind .bind_size = membind .alloc_size ;
891909 }
0 commit comments