Am Freitag, 19. November 2010 16:11:42 UTC+1 schrieb Olivier Ruskovini:
>
> Hello,
>
> I would like to use custom BASE32 alphabet with Base32Decoder class
> but my code doesn't work, it crashes cause of an inifinite Loop :
>
> CryptoPP::Base32Decoder decoder;
> static int decodingArray[256];
> static const byte myAlphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
>
> CryptoPP::Base32Decoder::InitializeDecodingLookupArray(decodingArray,myAlphabet,
>
>
> 32,true);
> b32_decoder.Initialize(CryptoPP::MakeParameters(CryptoPP::Name::DecodingLookupArray(),
>
>
> (const int *)decodingArray, false));
>
>
> It crashes here in "Initialize function" cause of an infinite loop (i
> have checked this with a debugger).
>
> Any idea?
>
> Thanx.
>
Hello,
I've also been trying to use CryptoPP::Base32Decoder with a custom
alphabet (for interop with Python's base64 module) and ran into the same
issue as OP. Here's my SSCCE, using Crypto++ 5.6.2:
#include <iostream>
#include <memory>
#include <string>
#include <cryptopp/base32.h>
#include <cryptopp/filters.h>
using namespace std;
using namespace CryptoPP;
byte const g_base32Alphabet[32 + 1] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
int g_base32Lookup[256];
int
main()
{
Base32Decoder::InitializeDecodingLookupArray
(g_base32Lookup, g_base32Alphabet, 32, /*caseInsensitive*/ false);
string const b32Text("NF2CA53POJVXGII=");
string text;
auto_ptr<Base32Decoder>
b32dec(new Base32Decoder(new StringSink(text)));
b32dec->Initialize
(MakeParameters(Name::DecodingLookupArray(),
static_cast<int const *>(&g_base32Lookup[0])),
0);
StringSource(b32Text, /*pumpAll*/ true, b32dec.release());
cout << text << endl;
}
The call to b32dec->Initialize() segfaults, due to a stack overflow
(gdb backtrace):
[...]
#174689 0x0804d183 in CryptoPP::Base32Decoder::IsolatedInitialize
(this=0x81aa050, parameters=...) at base32.cpp:23
#174690 0x080b8667 in CryptoPP::Filter::Initialize (this=0x81aa050,
parameters=..., propagation=-1) at filters.cpp:64
#174691 0x0804d183 in CryptoPP::Base32Decoder::IsolatedInitialize
(this=0x81aa050, parameters=...) at base32.cpp:23
#174692 0x080b8667 in CryptoPP::Filter::Initialize (this=0x81aa050,
parameters=..., propagation=-1) at filters.cpp:64
#174693 0x0804d183 in CryptoPP::Base32Decoder::IsolatedInitialize
(this=0x81aa050, parameters=...) at base32.cpp:23
#174694 0x080b8667 in CryptoPP::Filter::Initialize (this=0x81aa050,
parameters=..., propagation=-1) at filters.cpp:64
#174695 0x0804a28f in main () at demo.cc:29
The problem seems to be that Base32Decoder::IsolatedInitialize() calls
BaseN_Decoder::Initialize() (instead of IsolatedInitialize()?) which in
turn calls IsolatedInitialize() again and so forth..
With the following patch things seem to work as expected then:
diff -ru cryptopp562/base32.cpp cryptopp562.new/base32.cpp
--- cryptopp562/base32.cpp 2009-03-01 19:44:04.000000000 +0100
+++ cryptopp562.new/base32.cpp 2014-09-12 12:04:45.000000000 +0200
@@ -18,7 +18,7 @@
void Base32Decoder::IsolatedInitialize(const NameValuePairs ¶meters)
{
- BaseN_Decoder::Initialize(CombinedNameValuePairs(
+ BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(
parameters,
MakeParameters(Name::DecodingLookupArray(),
GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));
}
Anyhow, that's what I came up with but maybe someone in the know can shed
some (more) light.
Thanks and regards
Oliver
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#include <iostream>
#include <memory>
#include <string>
#include <cryptopp/base32.h>
#include <cryptopp/filters.h>
using namespace std;
using namespace CryptoPP;
byte const g_base32Alphabet[32 + 1] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
int g_base32Lookup[256];
int
main()
{
Base32Decoder::InitializeDecodingLookupArray
(g_base32Lookup, g_base32Alphabet, 32, /*caseInsensitive*/ false);
string const b32Text("NF2CA53POJVXGII=");
string text;
auto_ptr<Base32Decoder>
b32dec(new Base32Decoder(new StringSink(text)));
b32dec->Initialize
(MakeParameters(Name::DecodingLookupArray(),
static_cast<int const *>(&g_base32Lookup[0])),
0);
StringSource(b32Text, /*pumpAll*/ true, b32dec.release());
cout << text << endl;
}
diff -ru cryptopp562/base32.cpp cryptopp562.new/base32.cpp
--- cryptopp562/base32.cpp 2009-03-01 19:44:04.000000000 +0100
+++ cryptopp562.new/base32.cpp 2014-09-12 12:04:45.000000000 +0200
@@ -18,7 +18,7 @@
void Base32Decoder::IsolatedInitialize(const NameValuePairs ¶meters)
{
- BaseN_Decoder::Initialize(CombinedNameValuePairs(
+ BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(
parameters,
MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 5, true)));
}