@@ -78,25 +78,38 @@ func DeregisterReaderHandler(name string) {
78
78
79
79
func (mc * mysqlConn ) handleInFileRequest (name string ) (err error ) {
80
80
var rdr io.Reader
81
- data := make ( []byte , 4 + mc . maxWriteSize )
81
+ var data []byte
82
82
83
83
if strings .HasPrefix (name , "Reader::" ) { // io.Reader
84
84
name = name [8 :]
85
- handler , inMap := readerRegister [name ]
86
- if handler != nil {
85
+ if handler , inMap := readerRegister [name ]; inMap {
87
86
rdr = handler ()
88
- }
89
- if rdr == nil {
90
- if ! inMap {
91
- err = fmt .Errorf ("Reader '%s' is not registered" , name )
87
+ if rdr != nil {
88
+ data = make ([]byte , 4 + mc .maxWriteSize )
92
89
} else {
93
90
err = fmt .Errorf ("Reader '%s' is <nil>" , name )
94
91
}
92
+ } else {
93
+ err = fmt .Errorf ("Reader '%s' is not registered" , name )
95
94
}
96
95
} else { // File
97
96
name = strings .Trim (name , `"` )
98
97
if mc .cfg .allowAllFiles || fileRegister [name ] {
99
- rdr , err = os .Open (name )
98
+ var file * os.File
99
+ var fi os.FileInfo
100
+
101
+ if file , err = os .Open (name ); err == nil {
102
+ if fi , err = file .Stat (); err == nil {
103
+ rdr = file
104
+ if fileSize := int (fi .Size ()); fileSize <= mc .maxWriteSize {
105
+ data = make ([]byte , 4 + fileSize )
106
+ } else if fileSize <= mc .maxPacketAllowed {
107
+ data = make ([]byte , 4 + mc .maxWriteSize )
108
+ } else {
109
+ err = fmt .Errorf ("Local File '%s' too large: Size: %d, Max: %d" , name , fileSize , mc .maxPacketAllowed )
110
+ }
111
+ }
112
+ }
100
113
} else {
101
114
err = fmt .Errorf ("Local File '%s' is not registered. Use the DSN parameter 'allowAllFiles=true' to allow all files" , name )
102
115
}
0 commit comments