马一丁

Null pointer dereference after graph storage load failure

Showing 1 changed file with 22 additions and 0 deletions
@@ -1323,6 +1323,13 @@ def get_graph_data(report_id): @@ -1323,6 +1323,13 @@ def get_graph_data(report_id):
1323 1323
1324 graph = storage.load(graph_path) 1324 graph = storage.load(graph_path)
1325 1325
  1326 + # 检查图谱是否成功加载(文件可能损坏或格式错误)
  1327 + if graph is None:
  1328 + return jsonify({
  1329 + 'success': False,
  1330 + 'message': f'图谱文件损坏或格式错误: {report_id}'
  1331 + }), 500
  1332 +
1326 # 转换为 Vis.js 格式 1333 # 转换为 Vis.js 格式
1327 vis_nodes = [] 1334 vis_nodes = []
1328 vis_edges = [] 1335 vis_edges = []
@@ -1379,6 +1386,13 @@ def get_latest_graph(): @@ -1379,6 +1386,13 @@ def get_latest_graph():
1379 graph = storage.load(latest_path) 1386 graph = storage.load(latest_path)
1380 report_id = latest_path.parent.name if latest_path.parent else 'unknown' 1387 report_id = latest_path.parent.name if latest_path.parent else 'unknown'
1381 1388
  1389 + # 检查图谱是否成功加载(文件可能损坏或格式错误)
  1390 + if graph is None:
  1391 + return jsonify({
  1392 + 'success': False,
  1393 + 'message': '图谱文件损坏或格式错误'
  1394 + }), 500
  1395 +
1382 # 转换为 Vis.js 格式 1396 # 转换为 Vis.js 格式
1383 vis_nodes = [] 1397 vis_nodes = []
1384 vis_edges = [] 1398 vis_edges = []
@@ -1467,6 +1481,14 @@ def query_graph(): @@ -1467,6 +1481,14 @@ def query_graph():
1467 }), 404 1481 }), 404
1468 1482
1469 graph = storage.load(graph_path) 1483 graph = storage.load(graph_path)
  1484 +
  1485 + # 检查图谱是否成功加载(文件可能损坏或格式错误)
  1486 + if graph is None:
  1487 + return jsonify({
  1488 + 'success': False,
  1489 + 'message': '图谱文件损坏或格式错误'
  1490 + }), 500
  1491 +
1470 query_engine = QueryEngine(graph) 1492 query_engine = QueryEngine(graph)
1471 1493
1472 params = QueryParams( 1494 params = QueryParams(