Cardinal icon indicating copy to clipboard operation
Cardinal copied to clipboard

FIX: off-by-one error when identifying patch/Rack version by reading the magic sequence of a zstd-compressed patch

Open fixxxedpoint opened this issue 2 months ago • 2 comments

Cardinal stopped loading my patches and instead was showing cleared (default template) versions. I was expecting that it was caused by the fact that I have updated Cardinal recently and somehow Ardour was complaining about new version of my vst3 plugins. It appeared that Cardinal was incorrectly identifying Rack v2 type of patches with the zstd magic sequence.

fixxxedpoint avatar Nov 26 '25 18:11 fixxxedpoint

This is not really an off by one error, but potential misuse of sizeof(zstdMagic) which will return 5 here instead of the maybe expected 4. The fix should not be to manually try to force things, but just changing char type to uint8_t for which the compiler does not try to be smart and assume data to be a null-terminated string. Basically:

    static constexpr const uint8_t zstdMagic[] = {0x28, 0xb5, 0x2f, 0xfd};

falkTX avatar Nov 26 '25 18:11 falkTX

This is not really an off by one error, but potential misuse of sizeof(zstdMagic) which will return 5 here instead of the maybe expected 4. The fix should not be to manually try to force things, but just changing char type to uint8_t for which the compiler does not try to be smart and assume data to be a null-terminated string. Basically:

    static constexpr const uint8_t zstdMagic[] = {0x28, 0xb5, 0x2f, 0xfd};

Good point. Changed it. In general that file could use some refactor or at least we could limit the number of those #if CARDINAL_VARIANT_MINI || !defined(HEADLESS).

fixxxedpoint avatar Nov 26 '25 20:11 fixxxedpoint