Increase LINE_READER max line length to 16 MB
The previous 1 MB limit caused "Maximum line length exceeded" errors when loading schematics containing large embedded images or other long quoted tokens. The S-expression parser (DSNLEXER) requires entire quoted strings to fit within a single line buffer, so Prettify cannot split them across lines. Raise the limit from 1 MB to 16 MB and add regression tests. Fixes https://gitlab.com/kicad/code/kicad/-/issues/23162
This commit is contained in:
+1
-1
@@ -55,7 +55,7 @@
|
||||
KICOMMON_API wxString SafeReadFile( const wxString& aFilePath, const wxString& aReadType );
|
||||
|
||||
|
||||
#define LINE_READER_LINE_DEFAULT_MAX 1000000
|
||||
#define LINE_READER_LINE_DEFAULT_MAX 16000000
|
||||
#define LINE_READER_LINE_INITIAL_SIZE 5000
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,18 +23,94 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test suite for general string functions
|
||||
* Test suite for RICHIO and related formatting utilities
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
|
||||
// Code under test
|
||||
#include <richio.h>
|
||||
#include <io/kicad/kicad_io_utils.h>
|
||||
|
||||
#define wxUSE_BASE64 1
|
||||
#include <wx/base64.h>
|
||||
#include <wx/mstream.h>
|
||||
|
||||
|
||||
/**
|
||||
* Declare the test suite
|
||||
*/
|
||||
BOOST_AUTO_TEST_SUITE( RichIO )
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
/**
|
||||
* Verify that Prettify produces well-formed output for large (data ...) blocks such as
|
||||
* base64-encoded images, and that STRING_LINE_READER can read the result.
|
||||
*
|
||||
* Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23162
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE( PrettifyLargeImageData )
|
||||
{
|
||||
STRING_FORMATTER fmt;
|
||||
|
||||
fmt.Print( "(kicad_sch (version 20231120) (generator \"eeschema\")" );
|
||||
fmt.Print( "(image (at 0 0)" );
|
||||
|
||||
const size_t imageSize = 2 * 1024 * 1024;
|
||||
std::vector<uint8_t> fakeImage( imageSize, 0x42 );
|
||||
|
||||
wxMemoryOutputStream stream;
|
||||
stream.Write( fakeImage.data(), fakeImage.size() );
|
||||
|
||||
KICAD_FORMAT::FormatStreamData( fmt, *stream.GetOutputStreamBuffer() );
|
||||
|
||||
fmt.Print( ")" ); // close image
|
||||
fmt.Print( ")" ); // close kicad_sch
|
||||
|
||||
std::string buf = fmt.GetString();
|
||||
|
||||
KICAD_FORMAT::Prettify( buf );
|
||||
|
||||
BOOST_CHECK_NO_THROW(
|
||||
{
|
||||
STRING_LINE_READER reader( buf, "test" );
|
||||
|
||||
while( reader.ReadLine() )
|
||||
{
|
||||
// just consume
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verify that STRING_LINE_READER can handle prettified output containing a very long
|
||||
* quoted string (e.g. a property value that exceeds the old 1 MB limit).
|
||||
*
|
||||
* Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23162
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE( PrettifyLongQuotedString )
|
||||
{
|
||||
const size_t longLen = 1100000;
|
||||
std::string longValue( longLen, 'A' );
|
||||
|
||||
STRING_FORMATTER fmt;
|
||||
|
||||
fmt.Print( "(kicad_sch (version 20231120)" );
|
||||
fmt.Print( "(property \"Description\" %s (at 0 0 0))",
|
||||
fmt.Quotes( longValue ).c_str() );
|
||||
fmt.Print( ")" );
|
||||
|
||||
std::string buf = fmt.GetString();
|
||||
|
||||
KICAD_FORMAT::Prettify( buf );
|
||||
|
||||
BOOST_CHECK_NO_THROW(
|
||||
{
|
||||
STRING_LINE_READER reader( buf, "test" );
|
||||
|
||||
while( reader.ReadLine() )
|
||||
{
|
||||
// just consume
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user