@@ -20,6 +20,8 @@ limitations under the License.
2020#include " ../types.hpp"
2121#include " ../util/strings.hpp"
2222#include " ../transform/AliasCodec.hpp"
23+ #include " ../transform/BWT.hpp"
24+ #include " ../transform/BWTS.hpp"
2325#include " ../transform/EXECodec.hpp"
2426#include " ../transform/FSDCodec.hpp"
2527#include " ../transform/LZCodec.hpp"
@@ -494,6 +496,53 @@ static int testZRLTMalformed()
494496 return 0 ;
495497}
496498
499+ static int testTransformCapacityValidation ()
500+ {
501+ cout << endl
502+ << " Transform capacity validation" << endl;
503+
504+ Context ctx;
505+ ctx.putInt (" bsVersion" , BS_VERSION );
506+ kanzi::byte src[2 ] = { kanzi::byte (1 ), kanzi::byte (2 ) };
507+ kanzi::byte dst[2 ] = { kanzi::byte (0x7E ), kanzi::byte (0x7E ) };
508+
509+ {
510+ BWT tf;
511+ SliceArray<kanzi::byte> input (src, 1 , 0 );
512+ SliceArray<kanzi::byte> output (dst, 2 , 0 );
513+
514+ if (tf.forward (input, output, 2 ) != false ) {
515+ cout << " BWT should reject oversized input count" << endl;
516+ return 1 ;
517+ }
518+ }
519+
520+ {
521+ BWTS tf;
522+ SliceArray<kanzi::byte> input (src, 2 , 0 );
523+ SliceArray<kanzi::byte> output (dst, 0 , 0 );
524+
525+ if (tf.forward (input, output, 1 ) != false ) {
526+ cout << " BWTS should reject oversized output count" << endl;
527+ return 1 ;
528+ }
529+ }
530+
531+ {
532+ SBRT tf (SBRT ::MODE_RANK , ctx);
533+ SliceArray<kanzi::byte> input (src, 2 , 1 );
534+ SliceArray<kanzi::byte> output (dst, 2 , 0 );
535+
536+ if (tf.forward (input, output, 2 ) != false ) {
537+ cout << " SBRT should reject oversized remaining input count" << endl;
538+ return 1 ;
539+ }
540+ }
541+
542+ cout << " Transform capacity validation passed" << endl;
543+ return 0 ;
544+ }
545+
497546static Transform<kanzi::byte>* getByteTransform (string name, Context& ctx)
498547{
499548 if (name.compare (" SRT" ) == 0 )
@@ -999,6 +1048,11 @@ int TestTransforms_main(int argc, const char* argv[])
9991048
10001049 res = testZRLTMalformed ();
10011050
1051+ if (res != 0 )
1052+ return res;
1053+
1054+ res = testTransformCapacityValidation ();
1055+
10021056 if (res != 0 )
10031057 return res;
10041058
0 commit comments