Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubicon: Fix Nil Reference Panic From #1909 #1918

Merged
merged 1 commit into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,14 @@ func (a *RubiconAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
if request.Site != nil {
siteCopy := *request.Site
siteExtRP := rubiconSiteExt{RP: rubiconSiteExtRP{SiteID: rubiconExt.SiteId}}
target, err := updateExtWithIabAttribute(nil, siteCopy.Content.Data, []int{1, 2})
if err != nil {
errs = append(errs, err)
continue
if siteCopy.Content != nil {
target, err := updateExtWithIabAttribute(nil, siteCopy.Content.Data, []int{1, 2})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to verify siteCopy.Content is not nil before referencing siteCopy.Content.Data.

if err != nil {
errs = append(errs, err)
continue
}
siteExtRP.RP.Target = target
}
siteExtRP.RP.Target = target

siteCopy.Ext, err = json.Marshal(&siteExtRP)
if err != nil {
Expand Down Expand Up @@ -919,6 +921,9 @@ func resolveBidFloorAttributes(bidFloor float64, bidFloorCur string) (float64, s

func updateExtWithIabAttribute(target json.RawMessage, data []openrtb2.Data, segTaxes []int) (json.RawMessage, error) {
var segmentIdsToCopy = getSegmentIdsToCopy(data, segTaxes)
if len(segmentIdsToCopy) == 0 {
return target, nil
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case for an empty or missing data array looked odd, because the iab target element is still created, but is empty. Please advise on if this aspect should be removed.


extRPTarget := make(map[string]interface{})

Expand All @@ -938,7 +943,7 @@ func updateExtWithIabAttribute(target json.RawMessage, data []openrtb2.Data, seg
}

func getSegmentIdsToCopy(data []openrtb2.Data, segTaxValues []int) []string {
var segmentIdsToCopy = make([]string, 0)
var segmentIdsToCopy = make([]string, 0, len(data))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor memory optimization.


for _, dataRecord := range data {
if dataRecord.Ext != nil {
Expand Down
293 changes: 293 additions & 0 deletions adapters/rubicon/rubicontest/supplemental/no-site-content-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
},
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"site": {
"content": {
}
},
"user": {
"data": [
{
"ext": {
"segtax": 4
},
"segment": [
{
"id": "idToCopy"
}
]
},
{
"ext": {
"segtax": "someValue"
},
"segment": [
{
"id": "shouldNotBeCopied"
}
]
},
{
"ext": {
"segtax": "4"
},
"segment": [
{
"id": "shouldNotBeCopied2"
}
]
},
{
"ext": {
"segtax": 4
},
"segment": [
{
"id": "idToCopy2"
}
]
},
{
"ext": {
"segtax": [
4
]
},
"segment": [
{
"id": "shouldNotBeCopied3"
}
]
}
]
},
"imp": [
{
"id": "test-imp-id",
"instl": 1,
"video": {
"placement": 3,
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 1024,
"h": 576
},
"bidfloor": 1,
"bidfloorcur": "EuR",
"ext": {
"bidder": {
"video": {
},
"accountId": 1001,
"siteId": 113932,
"zoneId": 535510
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "uri?tk_xint=pbs-test-tracker",
"body": {
"id": "test-request-id",
"device": {
"ext": {
"rp": {
"pixelratio": 0
}
},
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
},
"site": {
"content": {
},
"ext": {
"rp": {
"site_id": 113932
}
},
"publisher": {
"ext": {
"rp": {
"account_id": 1001
}
}
}
},
"user": {
"data": [
{
"ext": {
"segtax": 4
},
"segment": [
{
"id": "idToCopy"
}
]
},
{
"ext": {
"segtax": "someValue"
},
"segment": [
{
"id": "shouldNotBeCopied"
}
]
},
{
"ext": {
"segtax": "4"
},
"segment": [
{
"id": "shouldNotBeCopied2"
}
]
},
{
"ext": {
"segtax": 4
},
"segment": [
{
"id": "idToCopy2"
}
]
},
{
"ext": {
"segtax": [
4
]
},
"segment": [
{
"id": "shouldNotBeCopied3"
}
]
}
],
"ext": {
"rp": {
"target": {
"iab": [
"idToCopy",
"idToCopy2"
]
}
}
}
},
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"imp": [
{
"id": "test-imp-id",
"instl": 1,
"video": {
"placement": 3,
"ext": {
"rp": {
"size_id": 203
}
},
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 1024,
"h": 576
},
"bidfloor": 1.2,
"bidfloorcur": "USD",
"ext": {
"rp": {
"track": {
"mint": "",
"mint_version": ""
},
"zone_id": 535510
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "some-test-ad",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"ext": {
"prebid": {
"type": "video"
}
}
}
],
"seat": "adman"
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "some-test-ad",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"ext": {
"prebid": {
"type": "video"
}
}
},
"type": "video"
}
]
}
]
}
Loading