]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
防止负数大小
authorqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 2 Nov 2022 01:00:35 +0000 (09:00 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Wed, 2 Nov 2022 01:00:35 +0000 (09:00 +0800)
CV/Var.go
F/B_I.go
F/B_I_test.go
Reply/fmp4Decode.go
bili_danmu.go

index 407440d733434ddf3ee5937b80f87b5d31a3cc68..35264f3aa0feb0090b6499f45c95b03712363a38 100644 (file)
--- a/CV/Var.go
+++ b/CV/Var.go
@@ -5,6 +5,7 @@ import (
        "errors"
        "flag"
        "io"
+       "testing"
        "time"
 
        file "github.com/qydysky/part/file"
@@ -49,7 +50,7 @@ type Common struct {
        ReqPool           *idpool.Idpool     //请求池
 }
 
-func (t *Common) init() Common {
+func (t *Common) Init() Common {
        t.Qn = map[int]string{ // no change
                20000: "4K",
                10000: "原画",
@@ -74,6 +75,7 @@ func (t *Common) init() Common {
                ckv     = flag.String("ckv", "", "自定义配置KV文件,将会覆盖config_K_v配置")
                roomIdP = flag.Int("r", 0, "roomid")
        )
+       testing.Init()
        flag.Parse()
        t.Roomid = *roomIdP
 
@@ -89,10 +91,6 @@ func (t *Common) init() Common {
                }
        }
 
-       if t.K_v.Len() == 0 {
-               panic("未能加载配置")
-       }
-
        if *ckv != "" {
                if bb, err := file.New(*ckv, 0, true).ReadAll(100, 1<<16); err != nil {
                        if errors.Is(err, io.EOF) {
@@ -178,7 +176,7 @@ func (t *Common) init() Common {
        return *t
 }
 
-var C = new(Common).init()
+var C = new(Common).Init()
 
 // 消息队列
 type Danmu_Main_mq_item struct {
index 8c93fa2d3133a2b6540b66c14e70fc7974592725..4fe5de11e481026b044eeeb3acd0d122557fed11 100644 (file)
--- a/F/B_I.go
+++ b/F/B_I.go
@@ -74,6 +74,17 @@ func Btoi64(b []byte, offset int) int64 {
        return btoi64(b[offset : offset+8])
 }
 
+func Btoi(b []byte, offset int, size int) int64 {
+       if size > 8 {
+               panic("最大8位")
+       }
+       var buf = b[offset : offset+size]
+       for len(buf) < 8 {
+               buf = append([]byte{0x00}, buf...)
+       }
+       return btoi64(buf)
+}
+
 func Btoi32(b []byte, offset int) int32 {
        for len(b) < 4 {
                b = append([]byte{0x00}, b...)
index bd1bc9c345189c7fe89b4dec5ee75c735a22f599..05d36e61f3e1f11c83d59e038b68f95a6c8cbba4 100644 (file)
@@ -3,7 +3,7 @@ package F
 import "testing"
 
 func TestBtoi32(t *testing.T) {
-       t.Log(Btoi64([]byte{0xd6, 0xfd, 0x62, 0x50}, 0))
+       t.Log(Btoi64([]byte{0xff, 0x0f, 0xff, 0xff}, 0))
 }
 
 func TestItob32(t *testing.T) {
index 919488a1a86690c972eda5d09b8f0eb342d29493..b1a2880c57b5f84d9dcecb86ab1c64309de6c7c7 100644 (file)
@@ -27,7 +27,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                }
                moovI = cu + moovI - 4
                cu = moovI
-               moovE := moovI + int(F.Btoi32(buf, moovI))
+               moovE := moovI + int(F.Btoi(buf, moovI, 4))
                if moovE > len(buf) {
                        return errors.New("moov包破损")
                }
@@ -40,7 +40,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                        }
                        trakI = cu + trakI - 4
                        cu = trakI
-                       trakE := trakI + int(F.Btoi32(buf, trakI))
+                       trakE := trakI + int(F.Btoi(buf, trakI, 4))
                        if trakE > moovE {
                                return errors.New("trak包破损")
                        }
@@ -52,7 +52,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                        }
                        tkhdI = cu + tkhdI - 4
                        cu = tkhdI
-                       tkhdE := tkhdI + int(F.Btoi32(buf, tkhdI))
+                       tkhdE := tkhdI + int(F.Btoi(buf, tkhdI, 4))
                        if tkhdE > trakE {
                                return errors.New("tkhd包破损")
                        }
@@ -64,7 +64,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                        }
                        mdiaI = cu + mdiaI - 4
                        cu = mdiaI
-                       mdiaE := mdiaI + int(F.Btoi32(buf, mdiaI))
+                       mdiaE := mdiaI + int(F.Btoi(buf, mdiaI, 4))
                        if mdiaE > trakE {
                                return errors.New("mdia包破损")
                        }
@@ -76,7 +76,7 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                        }
                        mdhdI = cu + mdhdI - 4
                        cu = mdhdI
-                       mdhdE := mdhdI + int(F.Btoi32(buf, mdhdI))
+                       mdhdE := mdhdI + int(F.Btoi(buf, mdhdI, 4))
                        if mdhdE > mdiaE {
                                return errors.New("mdhd包破损")
                        }
@@ -88,18 +88,18 @@ func (t *Fmp4Decoder) Init_fmp4(buf []byte) error {
                        }
                        hdlrI = cu + hdlrI - 4
                        cu = hdlrI
-                       hdlrE := hdlrI + int(F.Btoi32(buf, hdlrI))
+                       hdlrE := hdlrI + int(F.Btoi(buf, hdlrI, 4))
                        if hdlrE > mdiaE {
                                return errors.New("hdlr包破损")
                        }
 
-                       tackId := int(F.Btoi32(buf, tkhdI+20))
+                       tackId := int(F.Btoi(buf, tkhdI+20, 4))
                        if t.traks == nil {
                                t.traks = make(map[int]trak)
                        }
                        t.traks[tackId] = trak{
                                trackID:     tackId,
-                               timescale:   int(F.Btoi32(buf, mdhdI+20)),
+                               timescale:   int(F.Btoi(buf, mdhdI+20, 4)),
                                handlerType: buf[hdlrI+16],
                        }
                }
@@ -129,7 +129,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                }
                moofI = cu + moofI - 4
                cu = moofI
-               moofE := moofI + int(F.Btoi32(buf, moofI))
+               moofE := moofI + int(F.Btoi(buf, moofI, 4))
                if moofE > len(buf) {
                        break
                }
@@ -151,7 +151,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                        }
                        trafI = cu + trafI - 4
                        cu = trafI
-                       trafE := trafI + int(F.Btoi32(buf, trafI))
+                       trafE := trafI + int(F.Btoi(buf, trafI, 4))
                        if trafE > moofE {
                                break
                        }
@@ -164,7 +164,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                        }
                        tfhdI = cu + tfhdI - 4
                        cu = tfhdI
-                       tfhdE := tfhdI + int(F.Btoi32(buf, tfhdI))
+                       tfhdE := tfhdI + int(F.Btoi(buf, tfhdI, 4))
                        if tfhdE > trafE {
                                err = errors.New("tfhd包破损")
                                break
@@ -178,7 +178,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                        }
                        tfdtI = cu + tfdtI - 4
                        cu = tfdtI
-                       tfdtE := tfdtI + int(F.Btoi32(buf, tfdtI))
+                       tfdtE := tfdtI + int(F.Btoi(buf, tfdtI, 4))
                        if tfdtE > trafE {
                                err = errors.New("tfdt包破损")
                                break
@@ -192,7 +192,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                        }
                        trunI = cu + trunI - 4
                        cu = trunI
-                       trunE := trunI + int(F.Btoi32(buf, trunI))
+                       trunE := trunI + int(F.Btoi(buf, trunI, 4))
                        if trunE > trafE {
                                err = errors.New("trun包破损")
                                break
@@ -207,17 +207,17 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                        case 0:
                                timeSize = 4
                                timeStampIndex = tfdtI + 16
-                               timeStamp = int(F.Btoi32(buf, tfdtI+16))
+                               timeStamp = int(F.Btoi(buf, tfdtI+16, 4))
                        case 1:
                                timeSize = 8
                                timeStampIndex = tfdtI + 12
                                timeStamp = int(F.Btoi64(buf, tfdtI+12))
                        }
 
-                       track, ok := t.traks[int(F.Btoi32(buf, tfhdI+12))]
+                       track, ok := t.traks[int(F.Btoi(buf, tfhdI+12, 4))]
                        if !ok {
                                err = errors.New("找不到trak")
-                               // log.Default().Println(`cant find trak`, int(F.Btoi32(buf, tfhdI+12)))
+                               // log.Default().Println(`cant find trak`, int(F.Btoi(buf, tfhdI+12)))
                                continue
                        }
 
@@ -275,7 +275,7 @@ func (t *Fmp4Decoder) Seach_stream_fmp4(buf []byte) (keyframes [][]byte, last_av
                }
                mdatI = cu + mdatI - 4
                cu = mdatI
-               mdatE := mdatI + int(F.Btoi32(buf, mdatI))
+               mdatE := mdatI + int(F.Btoi(buf, mdatI, 4))
                if mdatE > len(buf) {
                        err = errors.New("mdat包破损")
                        break
index f0b594ed1bb2936d5e14b9802e38ddfcb2d8a0e7..66868ace865c3629dcef9b8784fdd25e58af4cf9 100644 (file)
@@ -66,6 +66,13 @@ func Start() {
                }
        }
 
+       //检查配置
+       {
+               if c.C.K_v.Len() == 0 {
+                       panic("未能加载配置")
+               }
+       }
+
        {
                var (
                        change_room_chan = make(chan struct{})