Github user maskit commented on the pull request: https://github.com/apache/trafficserver/pull/542#issuecomment-203732053 @jpeach I added some codes for debug and got these output. The rare case is happening. (I built with --enable-debug and ASAN using clang on OSX.) Output: ``` mime_hdr_set_accelerators_and_presence_bits(hdr 0x61d0001ab908, field 0x6250001aba98): &(mh->m_first_fblock.m_field_slots[0]) = 0x61d0001ab958 (int)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0xA (long)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x40000000A (ptrdiff_t)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x40000000A mime_hdr_field_slotnum(hdr 0x61d0001ab908, field 0x6250001ab998): first = 0x61d0001ab958 (int)(field - first) = 0x2 (long)(field - first) = 0x400000002 (ptrdiff_t)(field - first) = 0x400000002 ``` Debug code1: ``` c if ((int)(field - &(mh->m_first_fblock.m_field_slots[0])) >= 0 && (int)(field - &(mh->m_first_fblock.m_field_slots[0])) < MIME_FIELD_SLOTNUM_UNKNOWN && slot_num > UINT_MAX) { fprintf(stderr, "mime_hdr_set_accelerators_and_presence_bits(hdr %p, field %p): &(mh->m_first_fblock.m_field_slots[0]) = %p\n", mh, field, &(mh->m_first_fblock.m_field_slots[0])); fprintf(stderr, "(int)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%X\n", (int)(field - &(mh->m_first_fblock.m_field_slots[0]))); fprintf(stderr, "(long)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%lX\n", (long)(field - &(mh->m_first_fblock.m_field_slots[0]))); fprintf(stderr, "(ptrdiff_t)(field - &(mh->m_first_fblock.m_field_slots[0])) = 0x%tX\n", (ptrdiff_t)(field - &(mh->m_first_fblock.m_field_slots[0]))); } ``` Debug code2: ``` c if ((int)(field - first) >= 0 && (int)(field - first) < MIME_FIELD_BLOCK_SLOTS && block_slot > UINT_MAX) { fprintf(stderr, "mime_hdr_field_slotnum(hdr %p, field %p): first = %p\n", mh, field, first); fprintf(stderr, "(int)(field - first) = 0x%X\n", (int)(field - first)); fprintf(stderr, "(long)(field - first) = 0x%lX\n", (long)(field - first)); fprintf(stderr, "(ptrdiff_t)(field - first) = 0x%tX\n", (ptrdiff_t)(field - first)); } ``` However the problem doesn't seems to be caused by the optimization, adding ```MIMEFieldBlockImpl::contains(MIMEField*)``` is a good idea. It's readable and reusable. I'll add it. As for the tests, I had no idea. I came across the bug while I was testing HPACK, which just uses a MIMEHdr heavily. It may be possible to write tests for ```MIMEFieldBlockImpl::contains(MIMEField*)```. The test would be: 1. Create a mime field 2. Add 2^32 to the pointer of the mime field 3. Pass the modified pointer to contains() 4. Check if the result is false @zwoop The type conversions are in the initial commit on the git repo, so I think all versions should affect.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---