From 08bb3601bd40b08eed8d841e5f53b91e2a5e2dbc Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 24 Feb 2026 07:35:11 -0800 Subject: [PATCH] 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 --- include/richio.h | 2 +- qa/tests/common/test_richio.cpp | 88 ++++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/include/richio.h b/include/richio.h index f6c1aa75c0..2f3d817ac1 100644 --- a/include/richio.h +++ b/include/richio.h @@ -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 /** diff --git a/qa/tests/common/test_richio.cpp b/qa/tests/common/test_richio.cpp index e9cac58bd7..7fb549aef6 100644 --- a/qa/tests/common/test_richio.cpp +++ b/qa/tests/common/test_richio.cpp @@ -23,18 +23,94 @@ /** * @file - * Test suite for general string functions + * Test suite for RICHIO and related formatting utilities */ #include -// Code under test #include +#include + +#define wxUSE_BASE64 1 +#include +#include + -/** - * Declare the test suite - */ BOOST_AUTO_TEST_SUITE( RichIO ) -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file +/** + * 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 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()