Skip to content

回复:Bitcoind ​

首次公开证据

打开首次公开证据
查看 1 个交叉存档
来源说明

Published on GitHub in February 2024 as part of Martti Malmi's testimony in the COPA v. Wright trial

我把它放在 bitcoin.org/download/linux64-0.2.7.1.tar.gz。你拿到后可以把它删除。

我想了想可能是什么导致了你遇到的问题,并做了一项改动,这个构建中包含了它。这段代码可能不安全,不过它大概一直都碰巧没出问题。

在 util.cpp 中,旧代码:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     // Wrapper of wxGetTranslation returning the same const char* type
     // as was passed in
     static CCriticalSection cs;
     CRITICAL_BLOCK(cs)
     {
         // Look in cache
         static map<string, char*> mapCache;
         map<string, char*>::iterator mi = mapCache.find(pszEnglish);
         if (mi != mapCache.end())
             return (*mi).second;

         // wxWidgets translation
         const char* pszTranslated =
             wxGetTranslation(wxString(pszEnglish, wxConvUTF8)).utf8_str();

         // We don't cache unknown strings because caller might be
         // passing in a dynamic string and we would keep allocating
         // memory for each variation.
         if (strcmp(pszEnglish, pszTranslated) == 0)
             return pszEnglish;

         // Add to cache, memory doesn't need to be freed.  We only
         // cache because we must pass back a pointer to permanently
         // allocated memory.
         char* pszCached = new char[strlen(pszTranslated)+1];
         strcpy(pszCached, pszTranslated);
         mapCache[pszEnglish] = pszCached;
         return pszCached;
     }
     return NULL;
}

新代码:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     // Wrapper of wxGetTranslation returning the same const char* type
     // as was passed in
     static CCriticalSection cs;
     CRITICAL_BLOCK(cs)
     {
         // Look in cache
         static map<string, char*> mapCache;
         map<string, char*>::iterator mi = mapCache.find(pszEnglish);
         if (mi != mapCache.end())
             return (*mi).second;

         // wxWidgets translation
         wxString strTranslated = wxGetTranslation(wxString(pszEnglish,
             wxConvUTF8));

         // We don't cache unknown strings because caller might be
         // passing in a dynamic string and we would keep allocating
         // memory for each variation.
         if (strcmp(pszEnglish, strTranslated.utf8_str()) == 0)
             return pszEnglish;

         // Add to cache, memory doesn't need to be freed.  We only
         // cache because we must pass back a pointer to permanently
         // allocated memory.
         char* pszCached = new char[strlen(strTranslated.utf8_str())+1];
         strcpy(pszCached, strTranslated.utf8_str());
         mapCache[pszEnglish] = pszCached;
         return pszCached;
     }
     return NULL;
}

如果你仍然怀疑这段代码,为了测试,可以把它改成:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     return pszEnglish;
}

我尝试用 ddd 调试我的 bitcoind 构建,但到现在还不太成功。它最后总是会占满系统的全部内存,然后崩溃。你能否再把最新的 64 位 bitcoind 构建发给我,好让我看看问题是不是出在我的构建上?

英文原文 ​

展开英文原文

I put it at bitcoin.org/download/linux64-0.2.7.1.tar.gz. You can delete it when you've got it.

I thought about what might cause the problem you're having and made a change that this build includes. This might have been unsafe code, although it would probably always get lucky.

in util.cpp, old:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     // Wrapper of wxGetTranslation returning the same const char* type
     // as was passed in
     static CCriticalSection cs;
     CRITICAL_BLOCK(cs)
     {
         // Look in cache
         static map<string, char*> mapCache;
         map<string, char*>::iterator mi = mapCache.find(pszEnglish);
         if (mi != mapCache.end())
             return (*mi).second;

         // wxWidgets translation
         const char* pszTranslated =
             wxGetTranslation(wxString(pszEnglish, wxConvUTF8)).utf8_str();

         // We don't cache unknown strings because caller might be
         // passing in a dynamic string and we would keep allocating
         // memory for each variation.
         if (strcmp(pszEnglish, pszTranslated) == 0)
             return pszEnglish;

         // Add to cache, memory doesn't need to be freed.  We only
         // cache because we must pass back a pointer to permanently
         // allocated memory.
         char* pszCached = new char[strlen(pszTranslated)+1];
         strcpy(pszCached, pszTranslated);
         mapCache[pszEnglish] = pszCached;
         return pszCached;
     }
     return NULL;
}

new:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     // Wrapper of wxGetTranslation returning the same const char* type
     // as was passed in
     static CCriticalSection cs;
     CRITICAL_BLOCK(cs)
     {
         // Look in cache
         static map<string, char*> mapCache;
         map<string, char*>::iterator mi = mapCache.find(pszEnglish);
         if (mi != mapCache.end())
             return (*mi).second;

         // wxWidgets translation
         wxString strTranslated = wxGetTranslation(wxString(pszEnglish,
             wxConvUTF8));

         // We don't cache unknown strings because caller might be
         // passing in a dynamic string and we would keep allocating
         // memory for each variation.
         if (strcmp(pszEnglish, strTranslated.utf8_str()) == 0)
             return pszEnglish;

         // Add to cache, memory doesn't need to be freed.  We only
         // cache because we must pass back a pointer to permanently
         // allocated memory.
         char* pszCached = new char[strlen(strTranslated.utf8_str())+1];
         strcpy(pszCached, strTranslated.utf8_str());
         mapCache[pszEnglish] = pszCached;
         return pszCached;
     }
     return NULL;
}

If you still suspect this code, for testing you could change it to:

c
const char* wxGetTranslation(const char* pszEnglish)
{
     return pszEnglish;
}

I tried debugging my build of bitcoind with ddd debugger, but didn't have much success yet. It always ends up taking all the system's memory and finally crashes. Could you please send me again the latest 64 bit build of bitcoind, so I can see if the problem is about my build?

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。