🐛 索引嵌入块内容可能会导致内核崩溃 https://github.com/siyuan-note/siyuan/issues/7213

This commit is contained in:
Liang Ding 2023-02-01 09:53:40 +08:00
parent 7aea03db69
commit 70e2cd3987
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 12 additions and 4 deletions

View file

@ -197,6 +197,10 @@ func autoIndexEmbedBlock(embedBlocks []*sql.Block) {
for i, embedBlock := range embedBlocks {
stmt := strings.TrimPrefix(embedBlock.Markdown, "{{")
stmt = strings.TrimSuffix(stmt, "}}")
if !strings.Contains(strings.ToLower(stmt), "select") {
continue
}
queryResultBlocks := sql.SelectBlocksRawStmtNoParse(stmt, 102400)
for _, block := range queryResultBlocks {
embedBlock.Content += block.Content

View file

@ -468,14 +468,18 @@ func selectBlocksRawStmt(stmt string, limit int) (ret []*Block) {
defer rows.Close()
confLimit := !strings.Contains(strings.ToLower(stmt), " limit ")
var count, errCount int
for rows.Next() {
count++
if block := scanBlockRows(rows); nil != block {
ret = append(ret, block)
if confLimit && limit < len(ret) {
break
}
} else {
logging.LogWarnf("raw sql query [%s] failed: %s", stmt, err)
logging.LogWarnf("raw sql query [%s] failed: %s", stmt)
errCount++
}
if (confLimit && limit < count) || 7 < errCount {
break
}
}
return