<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - UBsan warns on access to 0 sized arrays in union"
   href="https://bugs.llvm.org/show_bug.cgi?id=44608">44608</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>UBsan warns on access to 0 sized arrays in union
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>manojgupta@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Copied from  Chrome OS bug
<a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1043405">https://bugs.chromium.org/p/chromium/issues/detail?id=1043405</a>

One of the programs in Chrome OS uses a 0 sized array inside a union.
ubsan errors on oob accesses to this member. Given that this array is 0 sized,
should accesses to it be treated differently?

Relevant struct snippet from
<a href="https://chromium.git.corp.google.com/chromiumos/platform/vboot_reference/+/f5367d598a985520a8c935f68ac90d295c7b8d8e/firmware/2lib/include/2sha.h">https://chromium.git.corp.google.com/chromiumos/platform/vboot_reference/+/f5367d598a985520a8c935f68ac90d295c7b8d8e/firmware/2lib/include/2sha.h</a>

struct vb2_hash {
        /* enum vb2_hash_algorithm. Fixed width for serialization.
           Single byte to avoid endianness issues. */
        uint8_t algo;
        /* Padding to align and to match existing CBFS attribute. */
        uint8_t reserved[3];
        /* The actual digest. Can add new types here as required. */
        union {
                uint8_t raw[0]; // triggers ubsan oob checks
#if VB2_SUPPORT_SHA1
                uint8_t sha1[VB2_SHA1_DIGEST_SIZE];
#endif
#if VB2_SUPPORT_SHA256
                uint8_t sha256[VB2_SHA256_DIGEST_SIZE];
#endif
#if VB2_SUPPORT_SHA512
                uint8_t sha512[VB2_SHA512_DIGEST_SIZE];
#endif
        } bytes;  /* This has a name so that it's easy to sizeof(). */
};</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>