-
Notifications
You must be signed in to change notification settings - Fork 204
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
vlq_base128_le is still incorrectrly compiled in C++ #685
Comments
#include <iostream>
#include <sstream>
#include "kaitai/kaitaistream.h"
#include "vlq_base128_le.h"
int main() {
// VlqBase128Le r = new VlqBase128Le(new KaitaiStream(new byte[] {0b1_0111000, 0b1_1100101, 0b1_1001111, 0b1_0101111, 0b0_1101101}));
std::string str("\xb8\xe5\xcf\xaf\x6d", 5);
std::istringstream is(str);
kaitai::kstream ks(&is);
vlq_base128_le_t r(&ks);
std::cout << " Actual value = 0x" << std::hex << r.value() << std::dec << std::endl;
// 0x6d5f3f2b8 = 0b1101101_0101111_1001111_1100101_0111000
std::cout << "Expected value = 0x6d5f3f2b8" << std::endl;
std::cout << " Actual value_signed = " << r.value_signed() << std::endl;
std::cout << "Expected value_signed = -5000400200" << std::endl;
}
FROM gcc:13
COPY main.cpp /usr/src/myapp/
WORKDIR /usr/src/myapp
RUN curl -fsSLO https://github.com/kaitai-io/formats-kaitai-io.github.io/raw/3c8309dd31fef81e66ef3c30f99998d7bd6ac16f/vlq_base128_le/src/cpp_stl_11/vlq_base128_le.{cpp,h}
RUN git clone -b 0.10 --depth 1 https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime.git
RUN g++ -O1 -std=c++11 -Wall -Wextra -Wpedantic -Wconversion -fsanitize=undefined -o myapp -DKS_STR_ENCODING_NONE -Ikaitai_struct_cpp_stl_runtime kaitai_struct_cpp_stl_runtime/kaitai/kaitaistream.cpp vlq_base128_le.cpp main.cpp
CMD ["./myapp"] pp@DESKTOP-89OPGF3 MINGW64 /c/temp/ksf-issue-685
$ docker build -t ksf-issue-685 .
[+] Building 0.2s (11/11) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 593B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/gcc:13 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 30B 0.0s
=> [1/6] FROM docker.io/library/gcc:13 0.0s
=> CACHED [2/6] COPY main.cpp /usr/src/myapp/ 0.0s
=> CACHED [3/6] WORKDIR /usr/src/myapp 0.0s
=> CACHED [4/6] RUN curl -fsSLO https://github.com/kaitai-io/formats-kaitai-io.github.io/raw/3c8309dd31fef81e66ef3c30f99998d7bd6ac16f/vlq_base128_le/src/cpp_stl_11/vlq_base128_le.{ 0.0s
=> CACHED [5/6] RUN git clone -b 0.10 --depth 1 https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime.git 0.0s
=> CACHED [6/6] RUN g++ -O1 -std=c++11 -Wall -Wextra -Wpedantic -Wconversion -o myapp -DKS_STR_ENCODING_NONE -Ikaitai_struct_cpp_stl_runtime kaitai_struct_cpp_stl_runtime/kaitai/ka 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:4d88eb098539c456e7bacfe4af5903322e5b3351ff757a49e92a23fab424de03 0.0s
=> => naming to docker.io/library/ksf-issue-685 0.0s
What's Next?
View a summary of image vulnerabilities and recommendations → docker scout quickview
pp@DESKTOP-89OPGF3 MINGW64 /c/temp/ksf-issue-685
$ docker run -it --rm ksf-issue-685
Actual value = 0x6d5f3f2b8
Expected value = 0x6d5f3f2b8
Actual value_signed = -5000400200
Expected value_signed = -5000400200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
The problem described in #559 still exists (at least with 0.10 version of the compiler which is what I have). It is not enough to add the cast just at end, because the computation is still done at the wrong type, and we just end up casting the wrong value at the end. You have to cast every single expression as well, have a closer look at the solution proposed by @mikhail-khalizev in #559.
The text was updated successfully, but these errors were encountered: