Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Test for the size of struct http_parser fails on 32 bit systems where there is padding/alignment for void* #526

Open
frmichael opened this issue Nov 30, 2020 · 6 comments

Comments

@frmichael
Copy link

frmichael commented Nov 30, 2020

Bonjour,

Porting http-parser to AIX, where there are 32 and 64 bit environments, there is a test on sizeof (struct http_parser) which fails due to 8 byte reservation for void* on both 32 and 64 bit compiles.

A clean option might be to change the void data element of struct http_parser to be a union of uint64 and void.

But this may not work if the 32 bit size of struct http_parser must remain at a total of 28 bytes (and in which case the test is in correct).

However, supposing that this is an error in the test code, I provisionally used the following patch for the 32 bit build

--- ./test.c.ORIG       2020-11-27 22:02:53 +0100
+++ ./test.c    2020-11-27 22:57:18 +0100
@@ -4234,7 +4234,7 @@
   printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version);
 
   printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));
-  assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + sizeof(void *));
+  assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + 2*sizeof(void *));
 
   //// API
   test_preserve_data();

We would like to ask for your expert advice on how best to resolve this issue.

Thanks.

@frmichael
Copy link
Author

frmichael commented Nov 30, 2020

The patch has been refined to apply to 32 and 64 bit builds (feedback appreciated)

--- ./test.c.ORIG       2020-11-30 14:17:06 +0100
+++ ./test.c    2020-11-30 14:21:43 +0100
@@ -4234,7 +4234,11 @@
   printf("http_parser v%u.%u.%u (0x%06lx)\n", major, minor, patch, version);
 
   printf("sizeof(http_parser) = %u\n", (unsigned int)sizeof(http_parser));
+#if defined(_AIX) && !defined(__64BIT__)
+  assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + 2*sizeof(void *));
+#else
   assert(sizeof(http_parser) == 4 + 4 + 8 + 2 + 2 + 4 + sizeof(void *));
+#endif
 
   //// API
   test_preserve_data();

@pallas
Copy link

pallas commented Nov 30, 2020

FYI, http-parser is dead.. long live https://github.com/nodejs/llhttp

@cbiedl
Copy link

cbiedl commented Dec 19, 2020

@frmichael: It seems you did include 4f15b7d since it disabled that assertion check for non-x86?

Still, that fix is incomplete as it still breaks on i386 (at least in Debian) where sizeof(void *) ==4 and therefore sizeof(http_parser) just 28. Ironically, comparing to the old 4 + 4 + 8 + 2 + 2 + 4 + sizeof(void *) makes the check pass.

@cbiedl
Copy link

cbiedl commented Dec 20, 2020

@frmichael: Sorry, forgot a "not" in my previous comment.

Also my suggested fix does not work for x32. le sigh.

@pallas
Copy link

pallas commented Dec 20, 2020

Again, I'd strongly suggest switching to nodejs/llhttp since it should be a mostly drop-in replacement. It's generated by llparse, but you can get the pre-compiled source from the release branch, i.e. https://github.com/nodejs/llhttp/tree/release

@cbiedl
Copy link

cbiedl commented Dec 24, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants