Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static build fails without overflow check #2544

Open
olegrok opened this issue Feb 21, 2024 · 2 comments
Open

Static build fails without overflow check #2544

olegrok opened this issue Feb 21, 2024 · 2 comments
Assignees
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@olegrok
Copy link

olegrok commented Feb 21, 2024

I got following error:

In member function 'Resize',
    inlined from 'Push' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:286:15,
    inlined from 'Attach' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:229:20:
/nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:299:47: error: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
/nix/store/WXPVL9V9N2S0SD6IQGIK43JK9X4HXFS4-x86_64-unknown-linux-musl-gcc-13.2.0/include/c++/13.2.0/new: In member function 'Attach':
/nix/store/WXPVL9V9N2S0SD6IQGIK43JK9X4HXFS4-x86_64-unknown-linux-musl-gcc-13.2.0/include/c++/13.2.0/new:128:26: note: in a call to allocation function 'operator new []' declared here
In member function 'Resize',
    inlined from 'Push' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:286:15,
    inlined from 'Attach' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:229:20,
    inlined from 'Attach' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:95:54,
    inlined from '__ct_base ' at /nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/trace/scope.h:33:9:
/nix/store/88WAXS933YDRH4ARHWAWF1G85H7L0F9Y-opentelemetry-static-x86_64-unknown-linux-musl-0.1.0/include/opentelemetry/context/runtime_context.h:299:47: error: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
/nix/store/WXPVL9V9N2S0SD6IQGIK43JK9X4HXFS4-x86_64-unknown-linux-musl-gcc-13.2.0/include/c++/13.2.0/new: In member function '__ct_base ':
/nix/store/WXPVL9V9N2S0SD6IQGIK43JK9X4HXFS4-x86_64-unknown-linux-musl-gcc-13.2.0/include/c++/13.2.0/new:128:26: note: in a call to allocation function 'operator new []' declared here
lto1: all warnings being treated as errors
make: *** [/tmp/nix-shell.D7rNKE/cc5tsruz.mk:2: /tmp/nix-shell.D7rNKE/cc9pcixh.ltrans0.ltrans.o] Error 1
lto-wrapper: fatal error: make returned 2 exit status
compilation terminated.
/nix/store/8hp6f8s9l90a45hjwbds79w6nwi15hm2-x86_64-unknown-linux-musl-binutils-2.40/bin/x86_64-unknown-linux-musl-ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

This patch fixes issue. But I'm not sure it's careful enough.

diff --git a/api/include/opentelemetry/context/runtime_context.h b/api/include/opentelemetry/context/runtime_context.h
index 2cd5b0ff..c32b4d63 100644
--- a/api/include/opentelemetry/context/runtime_context.h
+++ b/api/include/opentelemetry/context/runtime_context.h
@@ -10,6 +10,8 @@
 #include "opentelemetry/nostd/unique_ptr.h"
 #include "opentelemetry/version.h"
 
+#include <limits>
+
 OPENTELEMETRY_BEGIN_NAMESPACE
 namespace context
 {
@@ -296,6 +298,10 @@ class ThreadLocalContextStorage : public RuntimeContextStorage
       {
         new_capacity = 2;
       }
+      if (new_capacity >= std::numeric_limits<ssize_t>::max() / sizeof(Context))
+      {
+        new_capacity = std::numeric_limits<ssize_t>::max() / sizeof(Context);
+      }
       Context *temp = new Context[new_capacity];
       if (base_ != nullptr)
       {
@olegrok olegrok added the bug Something isn't working label Feb 21, 2024
@github-actions github-actions bot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 21, 2024
@ThomsonTan ThomsonTan added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 21, 2024
Copy link

This issue was marked as stale due to lack of activity.

@github-actions github-actions bot added the Stale label Apr 23, 2024
@meastp
Copy link
Contributor

meastp commented Apr 29, 2024

I also get this error - @marcalff any updates?

Perhaps you could use std::clamp for C++17 and up?

@github-actions github-actions bot removed the Stale label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

4 participants