Comments (7)
What is BOM? And how does it fail?
from q5go.
Could you attach the SGF file in question?
from q5go.
BOM explanation: https://en.wikipedia.org/wiki/Byte_order_mark
You may download a SGF file contains BOM at https://www.101weiqi.com/file/sgf/96/962980_1_时越_VS_杨鼎新.sgf
from q5go.
Hmm. That really doesn't seem valid according to the SGF spec (which really implies that SGF is a binary format, not a text format), but I guess if it's fairly common, we should try to special-case it.
from q5go.
Here's a patch that just ignores such a BOM. Does this work for the files you have? If not, could you attach more test cases?
diff --git a/src/sgfload.cc b/src/sgfload.cc
index a7cd3ae..ac48a8d 100644
--- a/src/sgfload.cc
+++ b/src/sgfload.cc
@@ -93,6 +93,20 @@ sgf *load_sgf (std::istream &in)
{
char nextch;
+ if (!in.get (nextch))
+ throw premature_eof ();
+ /* Look for (and discard) a UTF-8 BOM. Bogus, since SGF is a
+ binary file format, but it occurs in the wild. */
+ if (nextch == (char)0xEF) {
+ if (!in.get (nextch))
+ throw premature_eof ();
+ if (nextch != (char)0xBB)
+ throw broken_sgf ();
+ if (!in.get (nextch))
+ throw premature_eof ();
+ if (nextch != (char)0xBF)
+ throw broken_sgf ();
+ }
nextch = skip_whitespace (in);
if (nextch != '(')
throw broken_sgf ();
from q5go.
Here's a better version.
diff --git a/src/sgfload.cc b/src/sgfload.cc
index a7cd3ae..cdcacb3 100644
--- a/src/sgfload.cc
+++ b/src/sgfload.cc
@@ -93,7 +93,24 @@ sgf *load_sgf (std::istream &in)
{
char nextch;
- nextch = skip_whitespace (in);
+ if (!in.get (nextch))
+ throw premature_eof ();
+ /* Look for (and discard) a UTF-8 BOM. Bogus, since SGF is a
+ binary file format, but it occurs in the wild. */
+ if (nextch == (char)0xEF) {
+ if (!in.get (nextch))
+ throw premature_eof ();
+ if (nextch != (char)0xBB)
+ throw broken_sgf ();
+ if (!in.get (nextch))
+ throw premature_eof ();
+ if (nextch != (char)0xBF)
+ throw broken_sgf ();
+ if (!in.get (nextch))
+ throw premature_eof ();
+ }
+ if (isspace (nextch))
+ nextch = skip_whitespace (in);
if (nextch != '(')
throw broken_sgf ();
sgf *s = new sgf (parse_gametree (in));
from q5go.
so far, I only found UTF-8 encoded SGF files may contains BOM.
the patch works for me.
from q5go.
Related Issues (20)
- Add "unspecified" option for analysis rules HOT 4
- How to use svg/ascii part of q5Go for developers? HOT 6
- feature request: add "number of visits per board position" to the batch analysis HOT 2
- Defect: comments box font preference not kept
- feature request: make apparent that a node has comments
- Reduce memory usage of board representation HOT 23
- valgrind: "add directory" for batch analysis HOT 4
- Jump to a specific node from command line? HOT 6
- matches with inverted colors miscounted in pattern search HOT 4
- pattern search statistics has a wrong result in this case HOT 3
- Feature request: add numbers on stones starting from 1 in variations HOT 7
- Why does the evaluation graph not show an evaluation of each move in the game HOT 1
- Feature request: support the DD property of the SGF standard
- Feature request: support the AR and LN properties of the SGF standard
- Better GNOME aesthetic integration HOT 4
- Invalid move by the engine HOT 2
- how to build on Fedora (37)? error: Cannot find 'moc' HOT 1
- how to make two engines play each other HOT 2
- game information
- SVG file export without Ko info HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from q5go.