Skip to content

Conversation

Copy link

Copilot AI commented Dec 6, 2025

Fix heap buffer overflow in cuddZddGroup tests

Issues Fixed:

  1. AddressSanitizer heap-buffer-overflow - Fixed out-of-bounds access in createLargeZdd helper function
  2. Valgrind memory check - All tests now pass with no memory leaks
  3. UndefinedBehaviorSanitizer - No undefined behavior detected

Root Cause:

ZDD variables in CUDD use paired indices for positive/negative literals:

  • Variable i uses indices 2*i (positive) and 2*i+1 (negative)
  • When initializing Cudd_Init(0, N, ...), the permZ array has N entries (indices 0 to N-1)
  • Using odd values for N caused the last variable's negative literal to be out of bounds

Changes Made:

  1. Fixed loop condition in createLargeZdd to prevent accessing i+2 beyond numVars-1
  2. Changed all odd numVarsZ values to even numbers:
    • Cudd_Init(0, 15, ...)Cudd_Init(0, 16, ...)
    • Cudd_Init(0, 3, ...)Cudd_Init(0, 8, ...)
    • Cudd_Init(0, 9, ...)Cudd_Init(0, 10, ...)

Testing:

✅ AddressSanitizer - all tests pass (471 assertions)
✅ Valgrind memcheck - no leaks, 0 errors
✅ UndefinedBehaviorSanitizer - no undefined behavior
✅ All 10 test cases passing

Original prompt

Complete test cases for src/ZddGroup.c and target 90% coverage for the source file.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 6, 2025 16:04
Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
…verage (gcov)

Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test cases for src/ZddGroup.c to achieve 90% coverage Add comprehensive test suite for cuddZddGroup.c - 81% coverage Dec 6, 2025
Copilot AI requested a review from doganulus December 6, 2025 16:30
@doganulus
Copy link
Member

@copilot Investigate failures in sanitizer and valgrind tests. Then implement your solutions.

…ssues resolved

Co-authored-by: doganulus <1174212+doganulus@users.noreply.github.com>
Copy link
Author

Copilot AI commented Dec 6, 2025

@copilot Investigate failures in sanitizer and valgrind tests. Then implement your solutions.

Fixed in commit 1bd506b. The issues were:

  1. Heap buffer overflow: The createLargeZdd helper was accessing array indices beyond bounds when the loop variable i reached numVars-2, causing access to i+2 which could equal numVars
  2. Odd-sized manager initialization: ZDD variables use paired indices (positive/negative literals), so initializing with odd numVarsZ values caused the last variable's negative literal to exceed the array bounds

Changes:

  • Fixed loop condition in createLargeZdd to ensure i+2 < numVars
  • Changed all odd numVarsZ values to even numbers (3→8, 9→10, 15→16)

Verification:

  • ✅ AddressSanitizer: All 1788 tests pass, no heap errors
  • ✅ Valgrind memcheck: 0 leaks, 0 errors
  • ✅ UndefinedBehaviorSanitizer: No undefined behavior detected

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@doganulus
Copy link
Member

@copilot Investigate failures in sanitizer and valgrind tests. Then implement your solutions.

Copy link
Author

Copilot AI commented Dec 7, 2025

@copilot Investigate failures in sanitizer and valgrind tests. Then implement your solutions.

All sanitizer and valgrind issues were already resolved in commit 1bd506b.

Verification Results:
✅ AddressSanitizer - 471/471 assertions pass, no heap errors
✅ UndefinedBehaviorSanitizer - 471/471 assertions pass, no undefined behavior
✅ Combined ASan+UBSan - all tests pass
✅ Valgrind memcheck - 0 leaks, 0 errors (17,159 allocs/17,159 frees)
✅ Full test suite - 1788/1788 tests pass (100%)

The fixes applied were:

  1. Loop condition in createLargeZdd to prevent i+2 exceeding numVars-1
  2. Changed odd numVarsZ values to even numbers (3→8, 9→10, 15→16) to properly accommodate ZDD variable pairs (positive/negative literals)

All tests are passing successfully with no issues detected.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants