-
Notifications
You must be signed in to change notification settings - Fork 366
Description
The bug happens when your mother tongue is not English.
When I send the mapi.RopQueryRowsRequest request to the Exchange server with property tags mapi.PidTagDisplayName and mapi.PidTagFolderID.
setColumns.PropertyTags = make([]mapi.PropertyTag, 2)
setColumns.PropertyTags[0] = mapi.PidTagDisplayName
setColumns.PropertyTags[1] = mapi.PidTagFolderID
The response looks like this.

The response data itself looks correct with folderID and folderName, but when ruler tries to read these tags with mapi.UnmarshalRops, bug happens.
If the language setting of the current user is not English, the end of the folderName will be 0x00 0x00, bug if the language setting of the current user is English, the end of the folderName will be 0x00 0x00 0x00.
So the code should be like this, otherwise a NULL byte will be eaten.
//ReadUnicodeString read and return a unicode string
func ReadUnicodeString(pos int, buff []byte) ([]byte, int) {
//stupid hack as using bufio and ReadString(byte) would terminate too early
//would terminate on 0x00 instead of 0x0000
index := bytes.Index(buff[pos:], []byte{0x00, 0x00})
if buff[pos+index+2] == 0x00 {
index++ //unicode string end with 0x00 0x00 0x00
}
if index == -1 {
return nil, 0
}
str := buff[pos : pos+index]
return []byte(str), pos + index + 2
}
Also, When I send the mapi.RopQueryRowsRequest request to the Exchange Server 2016. I found that there is only one flag in the response.
So the code in the function (queryRows *RopQueryRowsResponse) Unmarshal(resp []byte, properties []PropertyTag) (int, error) should be like this
flag, pos = utils.ReadByte(pos, resp)
for k := 0; k < int(queryRows.RowCount); k++ {
trow := PropertyRow{}
//check if has flag (is flaggedpropertyrow)
for _, property := range properties {
if flag == 0x01 {
trow.Flag, pos = utils.ReadByte(pos, resp)
}
if trow.Flag != 0x00 {
[...]
} else if property.PropertyType == PtypString {
trow.ValueArray, pos = utils.ReadUnicodeString(pos, resp)
rows[k] = append(rows[k], trow)
} else if property.PropertyType == PtypBinary {