Commit f77fd43
fix: prevent segfault in gguf_loader legacy path on truncated models
Two bugs in the legacy (non-zero-copy) tensor loading paths:
1. fread path: when fseek/fread failed (truncated file), the loop
broke but the function returned true — leaving tensors with
uninitialized data. Now tracks load_ok flag and returns false
with proper cleanup (free buffer + context) on any failure.
2. mmap path: no bounds check before ggml_backend_tensor_set with
a pointer offset into the mmap region. On truncated files where
the mmap bounds check (zero-copy path) already failed and fell
through, data_off + off + nbytes could exceed mf.size, causing
SIGSEGV. Now checks offset+size against file size before access.
Both paths now print diagnostic messages identifying the failing
tensor name and sizes, making truncation issues easy to debug.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 7badb74 commit f77fd43
1 file changed
Lines changed: 36 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
680 | 681 | | |
681 | 682 | | |
682 | 683 | | |
| |||
687 | 688 | | |
688 | 689 | | |
689 | 690 | | |
690 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
691 | 694 | | |
| 695 | + | |
692 | 696 | | |
693 | | - | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
694 | 700 | | |
| 701 | + | |
695 | 702 | | |
696 | | - | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
697 | 707 | | |
| 708 | + | |
698 | 709 | | |
699 | 710 | | |
700 | 711 | | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
701 | 721 | | |
702 | 722 | | |
703 | 723 | | |
| |||
707 | 727 | | |
708 | 728 | | |
709 | 729 | | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
710 | 743 | | |
711 | 744 | | |
712 | 745 | | |
| |||
0 commit comments