View Issue Details

IDProjectCategoryView StatusLast Update
0009750ardourbugspublic2024-07-20 20:53
Reporterrantlivelintkale Assigned Tox42  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNUOSLinuxOS Version(any)
Product Version8.6 
Summary0009750: LV2 atoms misaligned
DescriptionFor reference https://gitlab.com/lv2/lv2/-/issues/67

In short:

building the test LV2 midi plugins with UB sanitizers:

clang -fno-omit-frame-pointer -g -fsanitize=undefined -shared-libasan <plugin>.c -shared -fPIC -o <plugin>.so

and running with:

LD_PRELOAD=$(clang -print-file-name=libclang_rt.ubsan_standalone.so)

catches the following bug at runtime:

src/eg-fifths.lv2/fifths.c:103:13: runtime error: member access within misaligned address 0x555558ad5cac for type 'LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:103:13
src/eg-fifths.lv2/fifths.c:103:13: runtime error: member access within misaligned address 0x555558ad5cb4 for type 'LV2_Atom', which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:103:13
/usr/include/lv2/atom/util.h:171:65: runtime error: member access within misaligned address 0x555558ad5cac for type 'const LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:171:65
/usr/include/lv2/atom/util.h:171:65: runtime error: member access within misaligned address 0x555558ad5cb4 for type 'const LV2_Atom', which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:171:65
/usr/include/lv2/atom/util.h:171:70: runtime error: load of misaligned address 0x555558ad5cb4 for type 'const uint32_t' (aka 'const unsigned int'), which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:171:70
/usr/include/lv2/atom/util.h:177:10: runtime error: store to misaligned address 0x555558addcec for type 'LV2_Atom_Event *', which requires 8 byte alignment
0x555558addcec: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:177:10
/usr/include/lv2/atom/util.h:177:13: runtime error: load of misaligned address 0x555558ad5cac for type 'const LV2_Atom_Event *', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:177:13
src/eg-fifths.lv2/fifths.c:116:41: runtime error: member access within misaligned address 0x555558ad5cac for type 'LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:116:41
src/eg-fifths.lv2/fifths.c:116:41: runtime error: member access within misaligned address 0x555558ad5cac for type 'union (unnamed union at /usr/include/lv2/atom/atom.h:216:3)', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:116:41
src/eg-fifths.lv2/fifths.c:116:46: runtime error: load of misaligned address 0x555558ad5cac for type 'int64_t' (aka 'long'), which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:116:46
src/eg-fifths.lv2/fifths.c:117:39: runtime error: member access within misaligned address 0x555558ad5cac for type 'LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:117:39
src/eg-fifths.lv2/fifths.c:117:39: runtime error: member access within misaligned address 0x555558ad5cb4 for type 'LV2_Atom', which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:117:39
src/eg-fifths.lv2/fifths.c:118:39: runtime error: member access within misaligned address 0x555558ad5cac for type 'LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:118:39
src/eg-fifths.lv2/fifths.c:118:39: runtime error: member access within misaligned address 0x555558ad5cb4 for type 'LV2_Atom', which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:118:39
src/eg-fifths.lv2/fifths.c:118:44: runtime error: load of misaligned address 0x555558ad5cb4 for type 'uint32_t' (aka 'unsigned int'), which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/eg-fifths.lv2/fifths.c:118:44
/usr/include/lv2/atom/util.h:110:49: runtime error: member access within misaligned address 0x555558ad5cac for type 'const LV2_Atom_Event', which requires 8 byte alignment
0x555558ad5cac: note: pointer points here
  00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:110:49
/usr/include/lv2/atom/util.h:110:49: runtime error: member access within misaligned address 0x555558ad5cb4 for type 'const LV2_Atom', which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:110:49
/usr/include/lv2/atom/util.h:110:54: runtime error: load of misaligned address 0x555558ad5cb4 for type 'const uint32_t' (aka 'const unsigned int'), which requires 8 byte alignment
0x555558ad5cb4: note: pointer points here
  00 00 00 00 03 00 00 00 10 00 00 00 90 43 64 00 00 00 00 00 00 00 00 00 41 03 02 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/lv2/atom/util.h:110:54
Steps To ReproduceBuild LV2 example plugins (or any MIDI plugins I guess) with UB sanitizers. Load them up in Ardour. Input some MIDI events.
TagsNo tags attached.

Activities

x42

2024-07-20 15:41

administrator   ~0028822

I constantly run Ardour with address sanitizer and never encountered this. And that includesLV2 Atom feedback from plugins to Ardour.

While Ardour currently uses malloc() for LV2 Atom buffers, malloc's memory is aligned for any built-in type, and that includes 64bit int and pointers.

But for good measure I have just changed this to use malign in Ardour 8.6-328-g8c583f8e20
Please test and let us know if that helps.

rantlivelintkale

2024-07-20 18:36

reporter   ~0028823

No, but comparing the code in Ardour with Jalv's lv2_evbuf.c (https://github.com/drobilla/jalv/blob/master/src/lv2_evbuf.c) this seems to fix the bug:

diff --git a/libs/ardour/lv2_evbuf.cc b/libs/ardour/lv2_evbuf.cc
index 816f383963..f9c9704065 100644
--- a/libs/ardour/lv2_evbuf.cc
+++ b/libs/ardour/lv2_evbuf.cc
@@ -35,6 +35,7 @@ struct ARDOUR::LV2_Evbuf {
        uint32_t capacity;
        uint32_t atom_Chunk;
        uint32_t atom_Sequence;
+ uint32_t pad; // for padding
        LV2_Atom_Sequence atom;
 };

at least I do not get the UB warnings with this change.

(Sorry if the formatting looks bad I do not know how to really format messages on Mantis.)

x42

2024-07-20 20:53

administrator   ~0028824

Thank you! Fixed in 8.6-329-g7567884111

Issue History

Date Modified Username Field Change
2024-07-20 14:31 rantlivelintkale New Issue
2024-07-20 14:31 rantlivelintkale Issue generated from: 0009748
2024-07-20 15:41 x42 Assigned To => x42
2024-07-20 15:41 x42 Status new => feedback
2024-07-20 15:41 x42 Note Added: 0028822
2024-07-20 18:36 rantlivelintkale Note Added: 0028823
2024-07-20 18:36 rantlivelintkale Status feedback => assigned
2024-07-20 20:53 x42 Status assigned => resolved
2024-07-20 20:53 x42 Resolution open => fixed
2024-07-20 20:53 x42 Note Added: 0028824