@@ -837,12 +837,20 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
837837 membind_t membind ;
838838 memset (& membind , 0 , sizeof (membind ));
839839
840- membind .alloc_size = ALIGN_UP (size , page_size );
840+ membind .alloc_size = ALIGN_UP_SAFE (size , page_size );
841+ if (membind .alloc_size == 0 ) {
842+ LOG_ERR ("size is too big, page align failed" );
843+ return membind ;
844+ }
841845 membind .page_size = page_size ;
842846 membind .addr = addr ;
843847 membind .pages = membind .alloc_size / membind .page_size ;
844848 if (provider -> nodeset_len == 1 ) {
845- membind .bind_size = ALIGN_UP (size , membind .page_size );
849+ membind .bind_size = ALIGN_UP_SAFE (size , membind .page_size );
850+ if (membind .bind_size == 0 ) {
851+ LOG_ERR ("size is too big, page align failed" );
852+ return membind ;
853+ }
846854 membind .bitmap = provider -> nodeset [0 ];
847855 return membind ;
848856 }
@@ -852,7 +860,12 @@ static membind_t membindFirst(os_memory_provider_t *provider, void *addr,
852860 size_t s = utils_fetch_and_add64 (& provider -> alloc_sum , size );
853861 membind .node = (s / provider -> part_size ) % provider -> nodeset_len ;
854862 membind .bitmap = provider -> nodeset [membind .node ];
855- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
863+ membind .bind_size =
864+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
865+ if (membind .bind_size == 0 ) {
866+ LOG_ERR ("size is too big, page align failed" );
867+ return membind ;
868+ }
856869 if (membind .bind_size > membind .alloc_size ) {
857870 membind .bind_size = membind .alloc_size ;
858871 }
@@ -888,7 +901,12 @@ static membind_t membindNext(os_memory_provider_t *provider,
888901 membind .node ++ ;
889902 membind .node %= provider -> nodeset_len ;
890903 membind .bitmap = provider -> nodeset [membind .node ];
891- membind .bind_size = ALIGN_UP (provider -> part_size , membind .page_size );
904+ membind .bind_size =
905+ ALIGN_UP_SAFE (provider -> part_size , membind .page_size );
906+ if (membind .bind_size == 0 ) {
907+ LOG_ERR ("part_size is too big, page align failed" );
908+ return membind ;
909+ }
892910 if (membind .bind_size > membind .alloc_size ) {
893911 membind .bind_size = membind .alloc_size ;
894912 }
0 commit comments